I have a MainWindow derived from QMainWindow and I re-implemented the closeEvent() handler.
void MainWindow::closeEvent(QCloseEvent *event)
{
if (this->okToContinue()) {
this->writeSettings();
//event->accept();
QMainWindow::closeEvent(event); // will work just fine even if this line omitted
} else {
event->ignore();
}
}
I've commented out the QMainWindow::closeEvent() to test the app will exit without the event propagating to the base implementation. Weirdly enough, it does exit.
I can just put event->ignore() outside of the if-else statement to prevent exiting but that's not the point.
Other event handlers such as keyPressEvent() don't work properly without the base implementation in their overrides but the closeEvent() does work without the base implementation. (Unless, of course, you reimplement everything)
void LineEdit::keyPressEvent(QCloseEvent *event)
{
QLineEdit::keyPressEvent(event); // will not show text in the widget if omitted
}
From what I've gathered in the documentation, once an event was handled by a widget, it does not propagate any further, unless explicitly allowed. (i.e. invoking the base's keyPressEvent() in the implementation of the child's keyPressEvent())
However a child's closeEvent() will close the application without invoking the base's closeEvent() in it's implementation. Seems like it propagates to somewhere else.
What makes this happen? Does QCloseEvent propagate to other widgets even after it was already handled?