diff options
author | Fabio Falsini <falsinsoft@gmail.com> | 2023-05-17 20:54:52 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-06-06 19:49:06 +0000 |
commit | 211b54ea470a0c7f69205f045593aaa4efd01072 (patch) | |
tree | b0ec6f916d8ce32806722e44a4ec61e59cc41c93 /src/widgets/dialogs/qcolordialog.cpp | |
parent | 2a7da1b3c8c4096d7c2b09f3fcc58e9cf47867cd (diff) |
Add flag to hide eye dropper button from QColorDialog
There are cases where this eye dropper control is useful and other
cases where it is useless. In case of an application connected with
graphics it's useful because it allows to select a precise color in
a very simple way. But in the case of a simple app where the user
only has to choose a color for, example, a graph this control is
useless and risks confusing the user (this kind of control is only
present in graphics software, not all "normal" users know what it
is for or understand its use). This patch add a flag to hide the
button.
As a drive-by change, the internal screenColorPickerButton pointer
is renamed to eyeDropperButton to be more consistent with the
qml ColorDialog.
[ChangeLog][QtWidgets][QColorDialog] Added a NoEyeDropperButton
option to hide the eye dropper button.
Change-Id: Ib29d5343383af97c1f488f9e33749517181aead7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qcolordialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qcolordialog.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 1bb65e6c24..a3b6fe935d 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -135,7 +135,7 @@ public: QPushButton *ok; QPushButton *cancel; QPushButton *addCusBt; - QPushButton *screenColorPickerButton; + QPushButton *eyeDropperButton = nullptr; QColor selectedQColor; int nextCust; bool smallDisplay; @@ -1642,8 +1642,8 @@ void QColorDialogPrivate::_q_pickScreenColor() addCusBt->setDisabled(true); buttons->setDisabled(true); - if (screenColorPickerButton) { - screenColorPickerButton->setDisabled(true); + if (eyeDropperButton) { + eyeDropperButton->setDisabled(true); const QPoint globalPos = QCursor::pos(); q->setCurrentColor(grabScreenColor(globalPos)); updateColorLabelText(globalPos); @@ -1673,7 +1673,7 @@ void QColorDialogPrivate::releaseColorPicking() lblScreenColorInfo->setText("\n"_L1); addCusBt->setDisabled(false); buttons->setDisabled(false); - screenColorPickerButton->setDisabled(false); + eyeDropperButton->setDisabled(false); } void QColorDialogPrivate::init(const QColor &initial) @@ -1736,13 +1736,13 @@ void QColorDialogPrivate::initWidgets() #if !defined(QT_SMALL_COLORDIALOG) if (supportsColorPicking()) { - screenColorPickerButton = new QPushButton(); - leftLay->addWidget(screenColorPickerButton); + eyeDropperButton = new QPushButton(); + leftLay->addWidget(eyeDropperButton); lblScreenColorInfo = new QLabel("\n"_L1); leftLay->addWidget(lblScreenColorInfo); - q->connect(screenColorPickerButton, SIGNAL(clicked()), SLOT(_q_pickScreenColor())); + q->connect(eyeDropperButton, SIGNAL(clicked()), SLOT(_q_pickScreenColor())); } else { - screenColorPickerButton = nullptr; + eyeDropperButton = nullptr; lblScreenColorInfo = nullptr; } #endif @@ -1882,8 +1882,8 @@ void QColorDialogPrivate::retranslateStrings() lblCustomColors->setText(QColorDialog::tr("&Custom colors")); addCusBt->setText(QColorDialog::tr("&Add to Custom Colors")); #if !defined(QT_SMALL_COLORDIALOG) - if (screenColorPickerButton) - screenColorPickerButton->setText(QColorDialog::tr("&Pick Screen Color")); + if (eyeDropperButton) + eyeDropperButton->setText(QColorDialog::tr("&Pick Screen Color")); #endif } @@ -2079,6 +2079,8 @@ void QColorDialog::setOptions(ColorDialogOptions options) if (!d->nativeDialogInUse) { d->buttons->setVisible(!(options & NoButtons)); d->showAlpha(options & ShowAlphaChannel); + if (d->eyeDropperButton) + d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton)); } } @@ -2098,6 +2100,7 @@ QColorDialog::ColorDialogOptions QColorDialog::options() const \value ShowAlphaChannel Allow the user to select the alpha component of a color. \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".) + \value NoEyeDropperButton Hide the \uicontrol{Eye Dropper} button. This value was added in Qt 6.6. \value DontUseNativeDialog Use Qt's standard color dialog instead of the operating system native color dialog. |