QColorDialog¶
The
QColorDialogclass provides a dialog widget for specifying colors. More…

Synopsis¶
Functions¶
def
currentColor()def
open(receiver, member)def
options()def
selectedColor()def
setCurrentColor(color)def
setOption(option[, on=true])def
setOptions(options)def
testOption(option)
Signals¶
def
colorSelected(color)def
currentColorChanged(color)
Static functions¶
def
customColor(index)def
customCount()def
getColor([initial=Qt.white[, parent=None[, title=””[, options=QColorDialog.ColorDialogOptions()]]]])def
setCustomColor(index, color)def
setStandardColor(index, color)def
standardColor(index)
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 theShowAlphaChanneloption 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. UsesetCustomColor()to set the custom colors, and usecustomColor()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
QColorDialogas well as other built-in Qt dialogs.![]()
See also
QColorQFileDialogQFontDialogStandard Dialogs Example
-
class
QColorDialog([parent=None])¶ QColorDialog(initial[, parent=None])
- param parent
- param initial
QColor
Constructs a color dialog with the given
parent.Constructs a color dialog with the given
parentand specifiedinitialcolor.
-
PySide2.QtWidgets.QColorDialog.ColorDialogOption¶ This enum specifies various options that affect the look and feel of a color dialog.
Constant
Description
QColorDialog.ShowAlphaChannel
Allow the user to select the alpha component of a color.
QColorDialog.NoButtons
Don’t display OK and Cancel buttons. (Useful for “live dialogs”.)
QColorDialog.DontUseNativeDialog
Use Qt’s standard color dialog instead of the operating system native color dialog.
See also
options
setOption()testOption()windowModality()
-
PySide2.QtWidgets.QColorDialog.colorSelected(color)¶ - Parameters
color –
QColor
-
PySide2.QtWidgets.QColorDialog.currentColor()¶ - Return type
QColor
See also
-
PySide2.QtWidgets.QColorDialog.currentColorChanged(color)¶ - Parameters
color –
QColor
-
static
PySide2.QtWidgets.QColorDialog.customColor(index)¶ - Parameters
index –
int- Return type
QColor
Returns the custom color at the given
indexas aQColorvalue.See also
-
static
PySide2.QtWidgets.QColorDialog.customCount()¶ - Return type
int
Returns the number of custom colors supported by
QColorDialog. All color dialogs share the same custom colors.
-
static
PySide2.QtWidgets.QColorDialog.getColor([initial=Qt.white[, parent=None[, title=""[, options=QColorDialog.ColorDialogOptions()]]]])¶ - Parameters
initial –
QColorparent –
QWidgettitle – unicode
options –
ColorDialogOptions
- Return type
QColor
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 toinitial. The dialog is a child ofparent. It returns an invalid (seeisValid()) color if the user cancels the dialog.The
optionsargument allows you to customize the dialog.
-
PySide2.QtWidgets.QColorDialog.open(receiver, member)¶ - Parameters
receiver –
QObjectmember – str
Opens the dialog and connects its
colorSelected()signal to the slot specified byreceiverandmember.The signal will be disconnected from the slot when the dialog is closed.
-
PySide2.QtWidgets.QColorDialog.options()¶ - Return type
ColorDialogOptions
See also
-
PySide2.QtWidgets.QColorDialog.selectedColor()¶ - Return type
QColor
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
currentColorproperty since the user can choose different colors before finally selecting the one to use.
-
PySide2.QtWidgets.QColorDialog.setCurrentColor(color)¶ - Parameters
color –
QColor
See also
-
static
PySide2.QtWidgets.QColorDialog.setCustomColor(index, color)¶ - Parameters
index –
intcolor –
QColor
Sets the custom color at
indexto theQColorcolorvalue.Note
This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the
DontUseNativeDialogoption.See also
-
PySide2.QtWidgets.QColorDialog.setOption(option[, on=true])¶ - Parameters
option –
ColorDialogOptionon –
bool
Sets the given
optionto be enabled ifonis true; otherwise, clears the givenoption.See also
options
testOption()
-
PySide2.QtWidgets.QColorDialog.setOptions(options)¶ - Parameters
options –
ColorDialogOptions
See also
-
static
PySide2.QtWidgets.QColorDialog.setStandardColor(index, color)¶ - Parameters
index –
intcolor –
QColor
Sets the standard color at
indexto theQColorcolorvalue.Note
This function does not apply to the Native Color Dialog on the macOS platform. If you still require this function, use the
DontUseNativeDialogoption.See also
-
static
PySide2.QtWidgets.QColorDialog.standardColor(index)¶ - Parameters
index –
int- Return type
QColor
Returns the standard color at the given
indexas aQColorvalue.See also
-
PySide2.QtWidgets.QColorDialog.testOption(option)¶ - Parameters
option –
ColorDialogOption- Return type
bool
Returns
trueif the givenoptionis enabled; otherwise, returns false.See also
options
setOption()
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.