Class: QgsColorDialog

A custom QGIS dialog for selecting a color.

Has many improvements over the standard Qt color picker dialog, including hue wheel supports, color swatches, and a color sampler.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorDialog

Base classes

QDialog

QWidget

QObject

QPaintDevice

Methods

color

Returns the current color for the dialog

setAllowOpacity

Sets whether opacity modification (transparency) is permitted for the color dialog.

setColor

Sets the current color for the dialog

setTitle

Sets the title for the color dialog

Static Methods

getColor

Returns a color selection from a color dialog.

Signals

currentColorChanged

Emitted when the dialog's color changes

class qgis.gui.QgsColorDialog[source]

Bases: QDialog

__init__(parent: QWidget | None = None, fl: Qt.WindowFlags | Qt.WindowType = QgsGuiUtils.ModalDialogFlags, color: QColor | Qt.GlobalColor = QColor())

Create a new color picker dialog

Parameters:
  • parent (Optional[QWidget] = None) – parent widget

  • fl (Union[Qt.WindowFlags, Qt.WindowType] = QgsGuiUtils.ModalDialogFlags) – window flags

  • color (Union[QColor, Qt.GlobalColor] = QColor()) – initial color for dialog

color(self) QColor[source]

Returns the current color for the dialog

Return type:

QColor

Returns:

dialog color

signal currentColorChanged(color: QColor)[source]

Emitted when the dialog’s color changes

Parameters:

color (QColor) – current color

static getColor(initialColor: QColor | Qt.GlobalColor, parent: QWidget | None, title: str | None = '', allowOpacity: bool = False) QColor[source]

Returns a color selection from a color dialog.

Parameters:
  • initialColor (Union[QColor, Qt.GlobalColor]) – the initial color of the selection dialog.

  • parent (Optional[QWidget]) – parent widget

  • title (Optional[str] = '') – the title of the dialog.

  • allowOpacity (bool = False) – set to True to allow modification of color opacity value (transparency)

Return type:

QColor

Returns:

Selected color on accepted() or initialColor on rejected().

setAllowOpacity(self, allowOpacity: bool)[source]

Sets whether opacity modification (transparency) is permitted for the color dialog. Defaults to True.

Parameters:

allowOpacity (bool) – set to False to disable opacity modification

setColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the current color for the dialog

Parameters:

color (Union[QColor, Qt.GlobalColor]) – desired color

setTitle(self, title: str | None)[source]

Sets the title for the color dialog

Parameters:

title (Optional[str]) – title for dialog box