Qt Event Filter eventfilter

Source: Internet
Author: User

Execute the required behavior in the monitored code. This can be achieved using Event Filter. Setting an Event Filter involves two steps:

1. Call installeventfilter () on the target object to register the monitoring object to the target object.
2. Process events of the target object in the eventfilter () method of the monitoring object.

Registering a monitoring object in the Ctor is a good place:
Customerinfodialog: customerinfodialog (qwidget * parent): qdialog (parent)
{
...
Firstnameedit-> installeventfilter (this );
Lastnameedit-> installeventfilter (this );
Cityedit-> installeventfilter (this );
Phonenumberedit-> installeventfilter (this );
}

Once the Event Filter is registered, events sent to firstnameedit, lastnameedit, cityedit, and phonenumberedit are first sent to the eventfilter () function of customerinfodialog before being sent to the original destination.

This is the eventfilter () function that receives these events:
Bool customerinfodialog: eventfilter (qobject * target, qevent * event)
{
If (target = firstnameedit | target = lastnameedit
| Target = cityedit | target = phonenumberedit)
{
If (Event-> type () = qevent: keypress)
{
Qkeyevent * keyevent = static_cast <qkeyevent *> (event );
If (keyevent-> key () = QT: key_space)
{
Focusnextchild ();
Return true;
}
}
}
Return qdialog: eventfilter (target, event );
}

Qt Event Filter eventfilter

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.