Home · All Classes · Modules

QColorDialog Class Reference
[QtGui module]

The QColorDialog class provides a dialog widget for specifying colors. More...

Inherits QDialog.

Types

Methods

Static Methods

Qt Signals


Detailed Description

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.

The Standard Dialogs example shows how to use QColorDialog as well as other built-in Qt dialogs.

A color dialog in the Plastique widget style.


Type Documentation

QColorDialog.ColorDialogOption

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

Constant Value Description
QColorDialog.ShowAlphaChannel 0x00000001 Allow the user to select the alpha component of a color.
QColorDialog.NoButtons 0x00000002 Don't display OK and Cancel buttons. (Useful for "live dialogs".)
QColorDialog.DontUseNativeDialog 0x00000004 Use Qt's standard color dialog on the Mac instead of Apple's native color panel.

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.

See also options, setOption(), testOption(), and windowModality().


Method Documentation

QColorDialog.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a color dialog with the given parent.

This function was introduced in Qt 4.5.

QColorDialog.__init__ (self, QColor initial, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

This function was introduced in Qt 4.5.

QColorDialog.changeEvent (self, QEvent e)

Reimplemented from QWidget.changeEvent().

QColor QColorDialog.currentColor (self)

int QColorDialog.customColor (int)

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

This function was introduced in Qt 4.5.

See also setCustomColor().

int QColorDialog.customCount ()

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

QColorDialog.done (self, int result)

Reimplemented from 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.

See also QDialog.done().

QColor QColorDialog.getColor (QColor initial = Qt.white, QWidget parent = None)

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.

On Symbian, this static function will use the native color dialog and not a QColorDialog. On Symbian the parameters title and parent has no relevance and the options parameter is only used to define if the native color dialog is used or not.

This function was introduced in Qt 4.5.

QColor QColorDialog.getColor (QColor initial, QWidget parent, QString title, ColorDialogOptions options = 0)

Pops up a modal color dialog, 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.

On Symbian, this static function will use the native color dialog and not a QColorDialog.

(int, bool ok) QColorDialog.getRgba (int initial = 4294967295, QWidget parent = None)

QColorDialog.open (self)

Shows the dialog as a window modal dialog, returning immediately.

This function was introduced in Qt 4.5.

See also QDialog.open().

QColorDialog.open (self, QObject receiver, SLOT()SLOT() 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.

QColorDialog.open (self, callable receiver)

ColorDialogOptions QColorDialog.options (self)

QColor QColorDialog.selectedColor (self)

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.

QColorDialog.setCurrentColor (self, QColor color)

QColorDialog.setCustomColor (int, int)

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

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

See also customColor().

QColorDialog.setOption (self, ColorDialogOption option, bool on = True)

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

See also options and testOption().

QColorDialog.setOptions (self, ColorDialogOptions options)

QColorDialog.setStandardColor (int, int)

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

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

QColorDialog.setVisible (self, bool visible)

Reimplemented from QWidget.setVisible().

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

bool QColorDialog.testOption (self, ColorDialogOption option)

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

This function was introduced in Qt 4.5.

See also options and setOption().


Qt Signal Documentation

void colorSelected (const QColor&)

This is the default overload of this signal.

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

See also color and currentColorChanged().

void currentColorChanged (const QColor&)

This is the default overload of this signal.

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

See also color and colorSelected().


PyQt 4.10.1 for MacOSCopyright © Riverbank Computing Ltd and Nokia 2012Qt 4.8.4