質問

Say I have QWidget::keyPressEvent(QKeyEvent *e) reimplemented in my subclass.

Is it necessary to call the base class' implementation at the end of it?

Example:

MyWidget::keyPressEvent(QKeyEvent *e)
{
    // my event handler...

    // now call parent event handler, necessary?
    QWidget::keyPressEvent(e);
}

If so, what's the point of doing that?

役に立ちましたか?

解決

If you do not act on the event you should always pass the event to the base class' implementation as it may act on it, or there may be an event filter installed for it. The default implementation of QWidget for instance closes popup widgets if the user presses Esc. So, to be sure not to break any event handling, always pass on events to the base class, unless you act on them.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top