From 44b7a1a37b18defcf27cee4fb5f6f8695387965d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 13 Oct 2021 16:39:19 +0200 Subject: 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 --- src/widgets/dialogs/qdialog.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/widgets/dialogs') 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(); -- cgit v1.2.3