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 <volker.hilsheimer@qt.io>
This commit is contained in:
Timur Pocheptsov 2023-10-20 14:54:06 +02:00 committed by Tor Arne Vestbø
parent 9c8651478b
commit 2d59f2e8ca

View File

@ -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<QPushButton *>(customButton)) {
// We can't support buttons with menus in native dialogs (yet)
if (pushButton->menu())
return false;
}
}
return QDialogPrivate::canBeNativeDialog();
}