QColorDialog 类提供用于指定颜色的对话框 Widget。 更多...
头: | #include <QColorDialog> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
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 ) |
virtual void | changeEvent (QEvent * e ) override |
virtual void | done (int result ) override |
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 对话框。
另请参阅 QColor , QFileDialog , QFontDialog ,和 标准对话框范例 .
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. |
ColorDialogOptions 类型是 typedef 对于 QFlags <ColorDialogOption>. It stores an OR combination of ColorDialogOption values.
另请参阅 options , setOption (), testOption (),和 windowModality ().
This property holds the currently selected color in the dialog
访问函数:
QColor | currentColor () const |
void | setCurrentColor (const QColor & color ) |
通知程序信号:
void | currentColorChanged (const QColor & color ) |
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 ().
[explicit]
QColorDialog::
QColorDialog
(
QWidget
*
parent
= nullptr)
构造颜色对话框采用给定 parent .
[explicit]
QColorDialog::
QColorDialog
(const
QColor
&
initial
,
QWidget
*
parent
= nullptr)
构造颜色对话框采用给定 parent 和指定 initial 颜色。
[虚拟]
QColorDialog::
~QColorDialog
()
销毁颜色对话框。
[override virtual protected]
void
QColorDialog::
changeEvent
(
QEvent
*
e
)
重实现: QWidget::changeEvent (QEvent *event).
[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 值。
另请参阅 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 (int r).
关闭对话框并将其结果代码设为 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 自变量允许您定制对话框。
打开对话框并连接其 colorSelected () 信号到槽,指定通过 receiver and member .
将从槽断开信号连接,当关闭对话框时。
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 ().
设置给定 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 (bool visible).
更改对话框的可见性。若 visible 为 true,展示对话框;否则,被隐藏。
[static]
QColor
QColorDialog::
standardColor
(
int
index
)
返回标准颜色在给定 index 作为 QColor 值。
另请参阅 setStandardColor ().
返回
true
若给定
option
被启用;否则,返回 false。