diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm index 23620a4bd7..cc1e8a98f2 100644 --- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm +++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm @@ -189,16 +189,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 ca7af90c15..ef1d8b04aa 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1661,6 +1661,11 @@ void QMessageBoxPrivate::setVisible(bool visible) { Q_Q(QMessageBox); + // Last minute setup + if (autoAddOkButton) + q->addButton(QMessageBox::Ok); + detectEscapeButton(); + if (canBeNativeDialog()) setNativeDialogVisible(visible); @@ -1705,13 +1710,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)