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