From aafed07dee5fd2d22518e49c4fa7798735e9e681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 3 Sep 2021 19:58:21 +0200 Subject: [PATCH] macOS: Don't show QMessageBox::about(Qt) as modal windows The system behavior is to not show these kinds of dialogs as modal, and we've documented that for QMessageBox. However, calling show() instead of exec() is not enough, as the default constructor of QMessageBox will set the modality of the widget to application-modal. We need to explicitly override this. [ChangLog][macOS] QMessageBox::about(Qt) now shows dialog non-modal, as documented. Pick-to: 6.2 Change-Id: I6bb59efb81feb23122276a9eede71b2f20c9d7c6 Reviewed-by: Volker Hilsheimer --- src/widgets/dialogs/qmessagebox.cpp | 2 ++ .../widgets/dialogs/qmessagebox/tst_qmessagebox.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 7b6148b1d2..ac2f8bd2d5 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1830,6 +1830,7 @@ void QMessageBox::about(QWidget *parent, const QString &title, const QString &te #else msgBox->d_func()->buttonBox->setCenterButtons(true); #endif + msgBox->setModal(false); msgBox->show(); #else msgBox->exec(); @@ -1915,6 +1916,7 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title) #else msgBox->d_func()->buttonBox->setCenterButtons(true); #endif + msgBox->setModal(false); msgBox->show(); #else msgBox->exec(); diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index b67f15458c..1363479897 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -127,11 +127,20 @@ void ExecCloseHelper::timerEvent(QTimerEvent *te) return; QWidget *modalWidget = QApplication::activeModalWidget(); - if (!m_testCandidate && modalWidget) m_testCandidate = modalWidget; - if (m_testCandidate && m_testCandidate == modalWidget) { + QWidget *activeWindow = QApplication::activeWindow(); + if (!m_testCandidate && activeWindow) + m_testCandidate = activeWindow; + + if (!m_testCandidate) + return; + + bool shouldHelp = (m_testCandidate->isModal() && m_testCandidate == modalWidget) + || (!m_testCandidate->isModal() && m_testCandidate == activeWindow); + + if (shouldHelp) { if (m_key == CloseWindow) { m_testCandidate->close(); } else {