Don't destroy the window if the QCloseEvent wasn't accepted

It's possible to override event() to receive the QCloseEvent and
do event->ignore() to prevent the window from closing.

Task-number: QTBUG-31019
Change-Id: I9abed47fca02a002b78727f98d678a824854adfc
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Shawn Rutledge 2013-05-06 16:36:20 +02:00 committed by The Qt Project
parent 1b91379323
commit df93d356df
2 changed files with 6 additions and 3 deletions

View File

@ -1896,9 +1896,11 @@ bool QWindow::event(QEvent *ev)
case QEvent::Close: {
Q_D(QWindow);
bool wasVisible = isVisible();
destroy();
if (wasVisible)
d->maybeQuitOnLastWindowClosed();
if (ev->isAccepted()) {
destroy();
if (wasVisible)
d->maybeQuitOnLastWindowClosed();
}
break; }
case QEvent::Expose:

View File

@ -330,6 +330,7 @@ protected:
virtual void showEvent(QShowEvent *);
virtual void hideEvent(QHideEvent *);
// TODO Qt 6 - add closeEvent virtual handler
virtual bool event(QEvent *);
virtual void keyPressEvent(QKeyEvent *);