summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-13 16:39:19 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-18 15:29:09 +0200
commit44b7a1a37b18defcf27cee4fb5f6f8695387965d (patch)
treedd479217e7c33adbb4b50de16811934f4457c35c /src/widgets/dialogs
parentdf359bcb703db5a8adbf14e88ba4ae0d54f0cfcd (diff)
Don't hide dialogs before closing them
When a dialog was accepted or rejected via done(), we used to only hide it, but as of 0246bfd40a2cc5ea9cfc035146e6dd865b334c68 we now close it. Closing a widget results in hiding it as part of handleClose, so we do not need to explicitly hide it before calling close(). In fact doing so prevents the lastWindowClosed logic from checking whether the window was visible before handling the close event, which is documented to be a requirement for a window triggering lastWindowClosed. We still need to hide the widget in case we don't end up closing it ourselves, to ensure QDialog::closeEvent accepts the close. The reason for the code in closeEvent seems a bit dubious, but that's left for future adventures. Change-Id: Ic32b965d495c08996c3a199bbee798df0206216c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qdialog.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 8b60e8952a..8b018969c8 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -153,7 +153,7 @@ void QDialogPrivate::close(int resultCode)
Q_Q(QDialog);
q->setResult(resultCode);
- q->hide();
+
if (!data.is_closing) {
// Until Qt 6.3 we didn't close dialogs, so they didn't receive a QCloseEvent.
// It is likely that subclasses implement closeEvent and handle them as rejection
@@ -171,6 +171,12 @@ void QDialogPrivate::close(int resultCode)
} closeEventEater;
q->installEventFilter(&closeEventEater);
QWidgetPrivate::close();
+ } else {
+ // If the close was initiated outside of QDialog we will end up
+ // here via QDialog::closeEvent calling reject(), in which case
+ // we need to hide the dialog to ensure QDialog::closeEvent does
+ // not ignore the close event. FIXME: Why is QDialog doing this?
+ q->hide();
}
resetModalitySetByOpen();