diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm index 56c3fceed25..5ea21e7b8af 100644 --- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm +++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm @@ -182,16 +182,6 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w for (auto customButton : customButtons) addButton(customButton.label, customButton.id, customButton.role); - - // QMessageDialog's logic for adding a fallback OK button if no other buttons - // are added depends on QMessageBox::showEvent(), which is too late when - // native dialogs are in use. To ensure there's always an OK button with a tag - // we recognize we add it explicitly here as a fallback. - if (!m_alert.buttons.count) { - addButton(platformTheme->standardButtonText(StandardButton::Ok), - StandardButton::Ok, ButtonRole::AcceptRole); - } - if (auto checkBoxLabel = options()->checkBoxLabel(); !checkBoxLabel.isNull()) { checkBoxLabel = QPlatformTheme::removeMnemonics(checkBoxLabel); m_alert.suppressionButton.title = checkBoxLabel.toNSString(); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index efe846900db..596bc9968ae 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1662,6 +1662,11 @@ void QMessageBoxPrivate::setVisible(bool visible) if (q->testAttribute(Qt::WA_WState_ExplicitShowHide) && q->testAttribute(Qt::WA_WState_Hidden) != visible) return; + // Last minute setup + if (autoAddOkButton) + q->addButton(QMessageBox::Ok); + detectEscapeButton(); + if (canBeNativeDialog()) setNativeDialogVisible(visible); @@ -1706,13 +1711,7 @@ QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const void QMessageBox::showEvent(QShowEvent *e) { Q_D(QMessageBox); - if (d->autoAddOkButton) { - addButton(Ok); - } - if (d->detailsButton) - addButton(d->detailsButton, QMessageBox::ActionRole); d->clickedButton = nullptr; - d->detectEscapeButton(); d->updateSize(); #if QT_CONFIG(accessibility)