Do I need to call the base class event handler in subclasses?

Let's say I have QWidget::keyPressEvent(QKeyEvent *e)

one overridden in my subclass.

Do I need to call the base class implementation at the end?

Example:

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

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

      

If so, what is the point of this?

+3


source to share


1 answer


If you are not taking part in the event, you should always pass the event to the base class implementation as it can act on it, or an event filter can be set on it. The default implementation QWidget

closes the popup widgets if the user presses Esc. Therefore, to avoid interrupting event processing, always pass events to the base class if you are not acting on them.



+5


source







All Articles