QColorDialog Class

The QColorDialog class provides a dialog widget for specifying colors. 更多...

头文件: #include <QColorDialog>
qmake: QT += widgets
基类: QDialog

公有类型

enum ColorDialogOption { ShowAlphaChannel, NoButtons, DontUseNativeDialog }
flags ColorDialogOptions

属性

公有函数

QColorDialog(QWidget *parent = Q_NULLPTR)
QColorDialog(const QColor &initial, QWidget *parent = Q_NULLPTR)
~QColorDialog()
QColor currentColor() const
void open(QObject *receiver, const char *member)
ColorDialogOptions options() const
QColor selectedColor() const
void setCurrentColor(const QColor &color)
void setOption(ColorDialogOption option, bool on = true)
void setOptions(ColorDialogOptions options)
bool testOption(ColorDialogOption option) const

重新实现的公有函数

virtual void setVisible(bool visible)

信号

void colorSelected(const QColor &color)
void currentColorChanged(const QColor &color)

静态公有成员

QColor customColor(int index)
int customCount()
QColor getColor(const QColor &initial = Qt::white, QWidget *parent = Q_NULLPTR, const QString &title = QString(), ColorDialogOptions options = ColorDialogOptions())
void setCustomColor(int index, QColor color)
void setStandardColor(int index, QColor color)
QColor standardColor(int index)
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject

重新实现的受保护函数

virtual void changeEvent(QEvent *e)
virtual void done(int result)
  • 6 个受保护的函数继承自 QDialog
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 5 个公有槽函数继承自 QDialog
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject
  • 1 个公有变量继承自 QObject
  • 6 个受保护的函数继承自 QDialog
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

The QColorDialog class provides a dialog widget for specifying colors.

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.

A color dialog in the Fusion widget style.

参见 QColor, QFileDialog, QFontDialog, and Standard Dialogs Example.

成员类型

enum QColorDialog::ColorDialogOption
flags QColorDialog::ColorDialogOptions

This enum specifies various options that affect the look and feel of a color dialog.

ConstantValueDescription
QColorDialog::ShowAlphaChannel0x00000001Allow the user to select the alpha component of a color.
QColorDialog::NoButtons0x00000002Don't display OK and Cancel buttons. (Useful for "live dialogs".)
QColorDialog::DontUseNativeDialog0x00000004Use Qt's standard color dialog instead of the operating system native color dialog.

This enum was introduced or modified in Qt 4.5.

The ColorDialogOptions type is a typedef for QFlags<ColorDialogOption>. It stores an OR combination of ColorDialogOption values.

参见 options, setOption(), testOption(), and windowModality().

属性

currentColor : QColor

This property holds the currently selected color in the dialog

访问函数:

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).

访问函数:

ColorDialogOptions options() const
void setOptions(ColorDialogOptions options)

参见 setOption() and testOption().

成员函数

QColorDialog::QColorDialog(QWidget *parent = Q_NULLPTR)

Constructs a color dialog with the given parent.

This function was introduced in Qt 4.5.

QColorDialog::QColorDialog(const QColor &initial, QWidget *parent = Q_NULLPTR)

Constructs a color dialog with the given parent and specified initial color.

This function was introduced in Qt 4.5.

QColorDialog::~QColorDialog()

Destroys the color dialog.

[virtual protected] void QColorDialog::changeEvent(QEvent *e)

重新实现 QWidget::changeEvent().

[signal] void QColorDialog::colorSelected(const QColor &color)

This signal is emitted just after the user has clicked OK to select a color to use. The chosen color is specified by color.

参见 color and currentColorChanged().

[signal] void QColorDialog::currentColorChanged(const QColor &color)

This signal is emitted whenever the current color changes in the dialog. The current color is specified by color.

Note: Notifier signal for property currentColor.

参见 color and colorSelected().

[static] QColor QColorDialog::customColor(int index)

Returns the custom color at the given index as a QColor value.

This function was introduced in Qt 4.5.

参见 setCustomColor().

[static] int QColorDialog::customCount()

Returns the number of custom colors supported by QColorDialog. All color dialogs share the same custom colors.

[virtual protected] void QColorDialog::done(int result)

重新实现 QDialog::done().

Closes the dialog and sets its result code to result. If this dialog is shown with exec(), done() causes the local event loop to finish, and exec() to return result.

参见 QDialog::done().

[static] QColor QColorDialog::getColor(const QColor &initial = Qt::white, QWidget *parent = Q_NULLPTR, const QString &title = QString(), ColorDialogOptions options = ColorDialogOptions())

Pops up a modal color dialog with the given window title (or "Select Color" if none is specified), lets the user choose a color, and returns that color. The color is initially set to initial. The dialog is a child of parent. It returns an invalid (see QColor::isValid()) color if the user cancels the dialog.

The options argument allows you to customize the dialog.

This function was introduced in Qt 4.5.

void QColorDialog::open(QObject *receiver, const char *member)

This is an overloaded function.

Opens the dialog and connects its colorSelected() signal to the slot specified by receiver and member.

The signal will be disconnected from the slot when the dialog is closed.

This function was introduced in Qt 4.5.

QColor QColorDialog::selectedColor() const

Returns the color that the user selected by clicking the OK or equivalent button.

Note: This color is not always the same as the color held by the currentColor property since the user can choose different colors before finally selecting the one to use.

[static] void QColorDialog::setCustomColor(int index, QColor color)

Sets the custom color at index to the QColor color value.

Note: This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the QColorDialog::DontUseNativeDialog option.

参见 customColor().

void QColorDialog::setOption(ColorDialogOption option, bool on = true)

Sets the given option to be enabled if on is true; otherwise, clears the given option.

参见 options and testOption().

[static] void QColorDialog::setStandardColor(int index, QColor color)

Sets the standard color at index to the QColor color value.

Note: This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the QColorDialog::DontUseNativeDialog option.

参见 standardColor().

[virtual] void QColorDialog::setVisible(bool visible)

重新实现 QWidget::setVisible().

Changes the visibility of the dialog. If visible is true, the dialog is shown; otherwise, it is hidden.

[static] QColor QColorDialog::standardColor(int index)

Returns the standard color at the given index as a QColor value.

This function was introduced in Qt 5.0.

参见 setStandardColor().

bool QColorDialog::testOption(ColorDialogOption option) const

Returns true if the given option is enabled; otherwise, returns false.

This function was introduced in Qt 4.5.

参见 options and setOption().