diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index 847a841cee2..93de7933d4e 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -883,9 +883,9 @@ QPlatformDialogHelper::StandardButtons QMessageDialogOptions::standardButtons() } int QMessageDialogOptions::addButton(const QString &label, QPlatformDialogHelper::ButtonRole role, - void *buttonImpl) + void *buttonImpl, int buttonId) { - const CustomButton b(d->nextCustomButtonId++, label, role, buttonImpl); + const CustomButton b(buttonId ? buttonId : d->nextCustomButtonId++, label, role, buttonImpl); d->customButtons.append(b); return b.id; } diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 78952f946aa..641ff681831 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -458,7 +458,7 @@ public: }; int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role, - void *buttonImpl = nullptr); + void *buttonImpl = nullptr, int buttonId = 0); void removeButton(int id); const QList &customButtons(); const CustomButton *customButton(int id); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 3f3289af3ea..ce324464aca 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -2841,22 +2841,37 @@ void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *) options->setStandardIcon(helperIcon(q->icon())); options->setIconPixmap(q->iconPixmap()); + // Clear up front, since we might have prepared earlier + options->clearCustomButtons(); + // Add standard buttons and resolve default/escape button - options->setStandardButtons(helperStandardButtons(q)); + auto standardButtons = helperStandardButtons(q); for (int button = QDialogButtonBox::StandardButton::FirstButton; button <= QDialogButtonBox::StandardButton::LastButton; button <<= 1) { auto *standardButton = buttonBox->button(QDialogButtonBox::StandardButton(button)); if (!standardButton) continue; + if (auto *platformTheme = QGuiApplicationPrivate::platformTheme()) { + if (standardButton->text() != platformTheme->standardButtonText(button)) { + // The standard button has been customized, so add it as + // a custom button instead. + const auto buttonRole = buttonBox->buttonRole(standardButton); + options->addButton(standardButton->text(), + static_cast(buttonRole), + standardButton, button); + standardButtons &= ~QPlatformDialogHelper::StandardButton(button); + } + } + if (standardButton == defaultButton) options->setDefaultButton(button); else if (standardButton == detectedEscapeButton) options->setEscapeButton(button); } + options->setStandardButtons(standardButtons); // Add custom buttons and resolve default/escape button - options->clearCustomButtons(); for (auto *customButton : customButtonList) { // Unless it's the details button, since we don't do any // plumbing for the button's action in that case.