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/gui | |
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/gui')
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.cpp | 17 | ||||
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.h | 7 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index f1370a07b8..7038954ea0 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -776,7 +776,8 @@ public: QList<QMessageDialogOptions::CustomButton> customButtons; int nextCustomButtonId; QPixmap iconPixmap; - bool enableSupressionCheckBox = false; + QString checkBoxLabel; + Qt::CheckState checkBoxState = Qt::Unchecked; }; QMessageDialogOptions::QMessageDialogOptions(QMessageDialogOptionsPrivate *dd) @@ -907,14 +908,20 @@ const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(i return (i < 0 ? nullptr : &d->customButtons.at(i)); } -void QMessageDialogOptions::setSupressionCheckBoxEnabled(bool enabled) +void QMessageDialogOptions::setCheckBox(const QString &label, Qt::CheckState state) { - d->enableSupressionCheckBox = enabled; + d->checkBoxLabel = label; + d->checkBoxState = state; } -bool QMessageDialogOptions::supressionCheckBoxEnabled() const +QString QMessageDialogOptions::checkBoxLabel() const { - return d->enableSupressionCheckBox; + return d->checkBoxLabel; +} + +Qt::CheckState QMessageDialogOptions::checkBoxState() const +{ + return d->checkBoxState; } QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button) diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 43d3dfe358..25543a70b8 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -451,8 +451,9 @@ public: const QList<CustomButton> &customButtons(); const CustomButton *customButton(int id); - void setSupressionCheckBoxEnabled(bool enabled); - bool supressionCheckBoxEnabled() const; + void setCheckBox(const QString &label, Qt::CheckState state); + QString checkBoxLabel() const; + Qt::CheckState checkBoxState() const; private: QMessageDialogOptionsPrivate *d; @@ -467,7 +468,7 @@ public: Q_SIGNALS: void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role); - void supressionCheckBoxChanged(bool checked); + void checkBoxStateChanged(Qt::CheckState state); private: QSharedPointer<QMessageDialogOptions> m_options; |