简体   繁体   中英

Event propagation in Qt

I've just the documentation on the Qt event system and the QEvent class . I'm interested in the behavior of the QObject::event() method. The documentation states:

This virtual function receives events to an object and should return true if the event e was recognized and processed.

What is the expected behavior when false is returned from the event() method? What else is attempted in order to handle the event? Is the event automatically forwarded to the parent object?

Note : I know the source is available, and I do have a copy. I'm ideally looking for some piece of documentation addressing this behavior.

I believe the best practice is to explicitly forward the events to the base-class event method if you do not wish to filter that event type (eg return QObject::event(event); ) since the event function delegates events to specific handlers (eg QWidget::keyPressEvent ).

QCoreApplication::notify propogates events based on the return value. On true , it considers the event as consumed and stops. Otherwise, the event is passed to the object's parent. For more information, see Events and Filters and Another Look at Events .

Some Events can be propagated.Event will be propagated to it's parent and it's parent recursively until it is processed. Take a look at this: https://doc.qt.io/archives/qq/qq11-events.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM