QColorDialog Class
The QColorDialog class provides a dialog widget for specifying colors. More...
| Header: | #include <QColorDialog> |
| qmake: | QT += widgets |
| Inherits: | QDialog |
Public Types
| enum | ColorDialogOption { ShowAlphaChannel, NoButtons, DontUseNativeDialog } |
Properties
- currentColor : QColor
- options : ColorDialogOptions
Public Functions
| QColor | currentColor() const |
| QColorDialog::ColorDialogOptions | options() const |
| void | setCurrentColor(const QColor &color) |
| void | setOptions(QColorDialog::ColorDialogOptions options) |
Signals
| void | currentColorChanged(const QColor &color) |
Detailed Description
The color dialog's function is to allow users to choose colors. For example, you might use this in a drawing program to allow the user to set the brush color.
The static functions provide modal color dialogs.
The static getColor() function shows the dialog, and allows the user to specify a color. This function can also be used to let users choose a color with a level of transparency: pass the ShowAlphaChannel option as an additional argument.
The user can store customCount() different custom colors. The custom colors are shared by all color dialogs, and remembered during the execution of the program. Use setCustomColor() to set the custom colors, and use customColor() to get them.
When pressing the "Pick Screen Color" button, the cursor changes to a haircross and the colors on the screen are scanned. The user can pick up one by clicking the mouse or the Enter button. Pressing Escape restores the last color selected before entering this mode.
The Standard Dialogs example shows how to use QColorDialog as well as other built-in Qt dialogs.

See also QColor, QFileDialog, QFontDialog, and Standard Dialogs Example.
Member Type Documentation
enum QColorDialog::ColorDialogOption
This enum specifies various options that affect the look and feel of a color dialog.
| Constant | Value | Description |
|---|---|---|
QColorDialog::ShowAlphaChannel | 0x00000001 | Allow the user to select the alpha component of a color. |
QColorDialog::NoButtons | 0x00000002 | Don't display OK and Cancel buttons. (Useful for "live dialogs".) |
QColorDialog::DontUseNativeDialog | 0x00000004 | Use Qt's standard color dialog instead of the operating system native color dialog. |
This enum was introduced or modified in Qt 4.5.
See also options, setOption(), testOption(), and windowModality().
Property Documentation
currentColor : QColor
This property holds the currently selected color in the dialog
Access functions:
| QColor | currentColor() const |
| void | setCurrentColor(const QColor &color) |
Notifier signal:
| void | currentColorChanged(const QColor &color) |
options : ColorDialogOptions
This property holds the various options that affect the look and feel of the dialog
By default, all options are disabled.
Options should be set before showing the dialog. Setting them while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).
Access functions:
| QColorDialog::ColorDialogOptions | options() const |
| void | setOptions(QColorDialog::ColorDialogOptions options) |
See also setOption() and testOption().