QColorDialog 类

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 = nullptr)
QColorDialog (const QColor & initial , QWidget * parent = nullptr)
virtual ~QColorDialog ()
QColor currentColor () const
void open (QObject * receiver , const char * member )
QColorDialog::ColorDialogOptions options () const
QColor selectedColor () const
void setCurrentColor (const QColor & color )
void setOption (QColorDialog::ColorDialogOption option , bool on = true)
void setOptions (QColorDialog::ColorDialogOptions options )
bool testOption (QColorDialog::ColorDialogOption option ) const

重实现公共函数

virtual void setVisible (bool visible ) override

信号

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 = nullptr, const QString & title = QString(), QColorDialog::ColorDialogOptions options = ColorDialogOptions())
void setCustomColor (int index , QColor color )
void setStandardColor (int index , QColor color )
QColor standardColor (int index )
const QMetaObject staticMetaObject

重实现保护函数

virtual void changeEvent (QEvent * e ) override
virtual void done (int result ) override

额外继承成员

详细描述

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.

静态函数提供模态颜色对话框。

静态 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.

用户可以存储 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 标准对话框 范例展示如何使用 QColorDialog 及其它内置 Qt 对话框。

A color dialog in the Fusion widget style.

另请参阅 QColor , QFileDialog , QFontDialog ,和 标准对话框范例 .

成员类型文档编制

enum QColorDialog:: ColorDialogOption
flags QColorDialog:: ColorDialogOptions

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

常量 描述
QColorDialog::ShowAlphaChannel 0x00000001 Allow the user to select the alpha component of a color.
QColorDialog::NoButtons 0x00000002 不显示 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.

该枚举在 Qt 4.5 引入或被修改。

ColorDialogOptions 类型是 typedef 对于 QFlags <ColorDialogOption>. It stores an OR combination of ColorDialogOption values.

另请参阅 options , setOption (), testOption (),和 windowModality ().

特性文档编制

currentColor : QColor

This property holds the currently selected color in the dialog

访问函数:

QColor currentColor () const
void setCurrentColor (const QColor & color )

通知程序信号:

void currentColorChanged (const QColor & color )

options : ColorDialogOptions

This property holds the various options that affect the look and feel of the dialog

默认情况下,所有选项是被禁用的。

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

访问函数:

QColorDialog::ColorDialogOptions options () const
void setOptions (QColorDialog::ColorDialogOptions options )

另请参阅 setOption () 和 testOption ().

成员函数文档编制

QColorDialog:: QColorDialog ( QWidget * parent = nullptr)

构造颜色对话框采用给定 parent .

该函数在 Qt 4.5 引入。

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

构造颜色对话框采用给定 parent 和指定 initial 颜色。

该函数在 Qt 4.5 引入。

[虚拟] QColorDialog:: ~QColorDialog ()

销毁颜色对话框。

[override 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 .

注意: 通知程序信号对于特性 currentColor .

另请参阅 color and colorSelected ().

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

返回自定义颜色在给定 index 作为 QColor 值。

该函数在 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.

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

重实现自 QDialog::done ().

关闭对话框并将其结果代码设为 result 。若此对话框的展示是采用 exec (),done() 导致本地事件循环的完成,且 exec () 返回 result .

另请参阅 QDialog::done ().

[static] QColor QColorDialog:: getColor (const QColor & initial = Qt::white, QWidget * parent = nullptr, const QString & title = QString(), QColorDialog::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 自变量允许您定制对话框。

该函数在 Qt 4.5 引入。

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

打开对话框并连接其 colorSelected () 信号到槽,指定通过 receiver and member .

将从槽断开信号连接,当关闭对话框时。

该函数在 Qt 4.5 引入。

QColor QColorDialog:: selectedColor () const

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

注意: 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 )

设置自定义颜色在 index QColor color 值。

注意: This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the QColorDialog::DontUseNativeDialog 选项。

另请参阅 customColor ().

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

设置给定 option 为被启用若 on 为 true;否则,清零给定 option .

另请参阅 options and testOption ().

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

设置标准颜色在 index QColor color 值。

注意: This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the QColorDialog::DontUseNativeDialog 选项。

另请参阅 standardColor ().

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

重实现自 QDialog::setVisible ().

更改对话框的可见性。若 visible 为 true,展示对话框;否则,被隐藏。

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

返回标准颜色在给定 index 作为 QColor 值。

该函数在 Qt 5.0 引入。

另请参阅 setStandardColor ().

bool QColorDialog:: testOption ( QColorDialog::ColorDialogOption option ) const

返回 true 若给定 option 被启用;否则,返回 false。

该函数在 Qt 4.5 引入。

另请参阅 options and setOption ().