From a69980e557b62dc088a1f96b2f358c2dbd365d61 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 20 Oct 2023 14:54:06 +0200 Subject: [PATCH] QMessageBox: Fall back to non-native dialog if button has menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's no plumbing in QMessageDialogOptions for supporting native dialog buttons with menus, and even if there was such plumbing, we don't know if our native dialogs could support them. As a workaround, detect the situation and automatically fall back to the non-native dialog, so the user doesn't need to set Qt::AA_DontUseNativeDialogs explicitly. Pick-to: 6.5 Fixes: QTBUG-118419 Change-Id: Iece7012909261b8869ce0ca23e45e8daaf4babc7 Reviewed-by: Volker Hilsheimer (cherry picked from commit 2d59f2e8caed71d4eceb1abe3ce17b7befb40559) Reviewed-by: Tor Arne Vestbø --- src/widgets/dialogs/qmessagebox.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 596bc9968ae..5d5ba6e117d 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -2824,6 +2824,14 @@ bool QMessageBoxPrivate::canBeNativeDialog() const if (strcmp(QMessageBox::staticMetaObject.className(), q->metaObject()->className()) != 0) return false; + for (auto *customButton : customButtonList) { + if (QPushButton *pushButton = qobject_cast(customButton)) { + // We can't support buttons with menus in native dialogs (yet) + if (pushButton->menu()) + return false; + } + } + return QDialogPrivate::canBeNativeDialog(); }