The ESC key for QT

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.