From 2d59f2e8caed71d4eceb1abe3ce17b7befb40559 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 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. Fixes: QTBUG-118419 Change-Id: Iece7012909261b8869ce0ca23e45e8daaf4babc7 Reviewed-by: Volker Hilsheimer --- 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 bb71a2370e4..5d0c84e9d49 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(); }