Qt 中的事件传播
我只是关于 Qt 事件系统 和 QEvent
类。我对 QObject::event()< 的行为感兴趣/code>
方法。文档指出:
此虚拟函数接收对象的事件,如果事件 e 被识别并处理,则应返回 true。
当 event()
方法返回 false
时,预期的行为是什么?为了处理该事件还尝试了什么?事件是否自动转发到父对象?
注意:我知道源代码可用,并且我有一个副本。我理想地寻找一些解决此行为的文档。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信,如果您不希望在事件发生后过滤该事件类型(例如
return QObject::event(event);
),则最佳实践是显式地将事件转发到基类事件方法函数将事件委托给特定的处理程序(例如QWidget::keyPressEvent
)。QCoreApplication::notify 根据返回值传播事件。如果为 true,它会将事件视为已消耗并停止。否则,事件将传递给对象的父对象。有关详细信息,请参阅事件和过滤器和再看看事件。
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 (e.g.
return QObject::event(event);
) since the event function delegates events to specific handlers (e.g.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.有些事件可以被传播。事件将被传播到它的父级,并递归地传播到它的父级,直到它被处理。看看这个:https://doc.qt.io/archives/ qq/qq11-events.html
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