QColorDialog Class
The QColorDialog class lets the user choose a color. More…
| Header | #include <QColorDialog> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QDialog |
List of all members, including inherited members
Public Types
| enum | ColorDialogOption |
| typedef | ColorDialogOptions |
Public Functions
| QColorDialog(QWidget *parent = nullptr) | |
| QColorDialog(const QColor &initial, QWidget *parent = nullptr) | |
| ~QColorDialog() | |
| void | setCurrentColor(const QColor &color) |
| QColor | currentColor() const |
| QColor | selectedColor() const |
| void | setOption(ColorDialogOption option, bool on = true) |
| bool | testOption(ColorDialogOption option) const |
| void | setOptions(ColorDialogOptions options) |
| ColorDialogOptions | options() const |
Signals
| void | currentColorChanged(const QColor &color) |
| void | colorSelected(const QColor &color) |
Static Public Members
| QColor | getColor(const QColor &initial = Qt::white, QWidget *parent = nullptr, const QString &title = QString(), ColorDialogOptions options = ColorDialogOptions()) |
| int | customCount() |
| QColor | customColor(int index) |
| void | setCustomColor(int index, QColor color) |
| QColor | standardColor(int index) |
| void | setStandardColor(int index, QColor color) |
Reimplemented Protected Functions
| void | done(int result) |
Detailed Description
The dialog has a grid of basic colors, a row of custom colors that the user can add to, a field of hues and saturations with a bar of values, and spin boxes and a text for the numbers. getColor() shows it and waits:
const QColor color = QColorDialog::getColor(current, window, "Text Color");
if (color.isValid())
setTextColor(color);
The custom colors are shared by all color dialogs of the application.
See also QColor.
Differences from Qt
The dialog is always drawn by Nt; there is no native dialog and no eye dropper. The basic colors are a grid of grays and hues of Nt's own. There is no open() with a receiver. The texts are not translated.
Member Type Documentation
enum QColorDialog::ColorDialogOption
Options for the look of the dialog. ColorDialogOptions is a typedef for QFlags<ColorDialogOption>.
| Constant | Description |
|---|---|
QColorDialog::ShowAlphaChannel | The user can choose the alpha channel too. |
QColorDialog::NoButtons | No OK and Cancel buttons, for a dialog that is used for its currentColorChanged() signal. |
QColorDialog::DontUseNativeDialog | Accepted for compatibility; the dialog is never native. |
QColorDialog::NoEyeDropperButton | Accepted for compatibility; there is no eye dropper. |
typedef QColorDialog::ColorDialogOptions
The ColorDialogOptions type is a typedef for QFlags<ColorDialogOption>. It stores an OR combination of ColorDialogOption values.
Member Function Documentation
QColorDialog::QColorDialog(QWidget *parent = nullptr)
Constructs a color dialog with the given parent. The current color is white.
QColorDialog::QColorDialog(const QColor &initial, QWidget *parent = nullptr)
Constructs a color dialog with the given parent and the initial current color.
QColorDialog::~QColorDialog()
Destroys the color dialog.
void QColorDialog::colorSelected(const QColor &color)
This signal is emitted when the dialog is accepted, with the chosen color.
QColor QColorDialog::currentColor() const
Returns the color that the user is picking.
See also setCurrentColor() and selectedColor().
void QColorDialog::currentColorChanged(const QColor &color)
This signal is emitted when the current color changes to color, as the user picks it.
QColor QColorDialog::customColor(int index)
Returns the custom color at index, or an invalid color if index is out of range.
See also setCustomColor().
int QColorDialog::customCount()
Returns the number of custom colors, 16.
void QColorDialog::done(int result)
Reimplements QDialog::done().
An accepted dialog records the selected color and emits colorSelected().
QColor QColorDialog::getColor(const QColor &initial = Qt::white, QWidget *parent = nullptr, const QString &title = QString(), ColorDialogOptions options = ColorDialogOptions())
Shows a color dialog with the given parent, window title and options, starting at the initial color, and waits for the user. Returns the chosen color, or an invalid color if the user canceled.
ColorDialogOptions QColorDialog::options() const
Returns the options of the dialog.
QColor QColorDialog::selectedColor() const
Returns the color that was chosen when the dialog was accepted, or an invalid color.
See also currentColor().
void QColorDialog::setCurrentColor(const QColor &color)
Sets the current color to color. Without ShowAlphaChannel the color is made opaque.
See also currentColor().
void QColorDialog::setCustomColor(int index, QColor color)
Sets the custom color at index to color.
See also customColor().
void QColorDialog::setOption(ColorDialogOption option, bool on = true)
Sets option if on is true, and clears it otherwise.
See also testOption().
void QColorDialog::setOptions(ColorDialogOptions options)
Sets the options of the dialog to options.
See also options().
void QColorDialog::setStandardColor(int index, QColor color)
Sets the basic color at index to color.
See also standardColor().
QColor QColorDialog::standardColor(int index)
Returns the basic color at index, from 0 to 47, or an invalid color if index is out of range.
See also setStandardColor().
bool QColorDialog::testOption(ColorDialogOption option) const
Returns whether option is set.