diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-03-08 10:27:48 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-03-09 09:41:33 +0100 |
commit | a0313c85a9b8ab6ba0ec273f0c8638e2f7b8cc18 (patch) | |
tree | 514e55d3c4bbd60e766b78db22f84107d9b9bae9 /src/widgets/dialogs | |
parent | 9255820ad591645897d261b795b5649b8d9a313f (diff) |
Plumb QMessageBox::setCheckBox() through QPlatformMessageDialogHelper
Without this plumbing we have no way of knowing if the QMessageBox
has a checkbox set, and can't decide to skip the native dialog,
leaving the user without the expected checkbox.
As the suppression checkbox on macOS can be customized, we can use
this plumbing to actually provide native dialog support for generic
check boxes.
This mechanism can also be used by QErrorMessage, which now matches
behavior between native and non-native dialogs in terms of the label
of the checkbox and its initial state. We might want to tweak this
in the future, since user's might expect the suppression label and
state to match the system default, but that's something we can
expose from the platform theme if so, and should apply equally
to the non-native dialog.
Fixes: QTBUG-111803
Pick-to: 6.5.0 6.5
Change-Id: Ied9fc34383fe79fbd8437592ad1c1993b9396178
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qerrormessage.cpp | 8 | ||||
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 11 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp index 374cdb53cc..5a6d529fc2 100644 --- a/src/widgets/dialogs/qerrormessage.cpp +++ b/src/widgets/dialogs/qerrormessage.cpp @@ -63,9 +63,9 @@ void QErrorMessagePrivate::initHelper(QPlatformDialogHelper *helper) { Q_Q(QErrorMessage); auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(helper); - QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::supressionCheckBoxChanged, q, - [this](bool supressionChecked) { - again->setChecked(!supressionChecked); + QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, q, + [this](Qt::CheckState state) { + again->setCheckState(state); } ); QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked, q, @@ -86,7 +86,7 @@ void QErrorMessagePrivate::helperPrepareShow(QPlatformDialogHelper *helper) options->setText(QErrorMessage::tr("An error occurred")); options->setInformativeText(currentMessage); options->setStandardIcon(QMessageDialogOptions::Critical); - options->setSupressionCheckBoxEnabled(true); + options->setCheckBox(again->text(), again->checkState()); messageDialogHelper->setOptions(options); } diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index cf731b2961..cdd073350b 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -2682,6 +2682,15 @@ void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h) Q_Q(QMessageBox); QObject::connect(h, SIGNAL(clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)), q, SLOT(_q_clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole))); + + auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(h); + QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, q, + [this](Qt::CheckState state) { + if (checkbox) + checkbox->setCheckState(state); + } + ); + static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options); } @@ -2720,6 +2729,8 @@ void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *) options->setStandardIcon(helperIcon(q->icon())); options->setIconPixmap(q->iconPixmap()); options->setStandardButtons(helperStandardButtons(q)); + if (checkbox) + options->setCheckBox(checkbox->text(), checkbox->checkState()); } void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) |