ESC key for everyone is really familiar with, in the QT ESC will also be the default for some events triggered, today, the ESC key test, and suddenly found that not as I imagined, pressing the ESC key in Qdialog will call The Reject () method by default instead of Closeevent (Qcloseevent *event) or other events. So how do you manage and operate the ESC key here?
1. Re-implement The Reject () method
void Logindialog::reject ()
{
Close the window, not necessarily close (), can re-execute other events
This->close ();
}
2, rewrite keypressevent (qkeyevent *event)
void Logindialog::keypressevent (Qkeyevent *event)
{
Switch (Event->key ())
{
Perform interface exit, override Esc key, otherwise override reject () method
Case Qt::key_escape:
This->close ();
Break
Default
Qdialog::keypressevent (event);
}
}
Both of these methods can solve the ESC key trigger problem! Of course this is only the case in Qdialog, in Qwidget can also be keypressevent (qkeyevent *event) to develop the function of the ESC key, but then rewrite reject () will not be able to assume that it does not perform reject by default ( ), the specific can be tested!
Http://blog.sina.com.cn/s/blog_a6fb6cc90101b1v3.html
The ESC key for QT