From bc415a432a70ca2c0e6565ca062a76949a01c36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 24 Oct 2023 17:09:13 +0200 Subject: [PATCH] macOS: Respect QPlatformDialogHelper::ButtonLayout in native alerts The buttons in QMessageDialogOptions do not have any order that we can rely on. The standard buttons is just a bit mask, so any ordering done on the QMessageBox side is lost. The custom buttons are ordered in the same order the user added them, but this is not really the order we want them to appear in the dialog either, as we have a well defined order between roles provided by QPlatformDialogHelper. We now follow the QPlatformDialogHelper::ButtonLayout order for macOS, using the same heuristics for multiple Accept role buttons as QDialogButtonBox. For buttons with the same role, QMessageBox will respect the order they were added in, but this is not something we can do for the standard buttons, as long as they are flattened to a bit mask. Pick-to: 6.5 Change-Id: I401f202a7c2d83dc253e988531ad145624c97580 Reviewed-by: Timur Pocheptsov (cherry picked from commit 0366b554c936e3257797f9c281c1cbd76e426dd3) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/cocoa/qcocoamessagedialog.mm | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm index 82a4c90c236..993e645a67e 100644 --- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm +++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm @@ -151,6 +151,8 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w // button). If an explicit default or escape button has been set, we respect these, // and otherwise we fall back to role-based default and escape buttons. + qCDebug(lcQpaDialogs).verbosity(0) << "Adding button" << title << "with" << role; + if (!defaultButton && role == AcceptRole) defaultButton = tag; @@ -186,19 +188,63 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w button.tag = tag; }; + // Resolve all dialog buttons from the options, both standard and custom + + struct Button { QString title; int identifier; ButtonRole role; }; + std::vector