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>bb10
parent
2a7da1b3c8
commit
211b54ea47
|
|
@ -157,7 +157,8 @@ public:
|
|||
enum ColorDialogOption {
|
||||
ShowAlphaChannel = 0x00000001,
|
||||
NoButtons = 0x00000002,
|
||||
DontUseNativeDialog = 0x00000004
|
||||
DontUseNativeDialog = 0x00000004,
|
||||
NoEyeDropperButton = 0x00000008
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ public:
|
|||
enum ColorDialogOption {
|
||||
ShowAlphaChannel = 0x00000001,
|
||||
NoButtons = 0x00000002,
|
||||
DontUseNativeDialog = 0x00000004
|
||||
DontUseNativeDialog = 0x00000004,
|
||||
NoEyeDropperButton = 0x00000008
|
||||
};
|
||||
Q_ENUM(ColorDialogOption)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue