Class: QgsColorSwatchGrid

A grid of color swatches, which allows for user selection.

Colors are taken from an associated QgsColorScheme.

See also

QgsColorGridAction

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorSwatchGrid

Base classes

QWidget

QObject

QPaintDevice

Methods

baseColor

Gets the base color for the widget

colors

Gets the list of colors shown in the grid

context

Gets the current context for the grid

refreshColors

Reload colors from scheme and redraws the widget

setBaseColor

Sets the base color for the widget

setContext

Sets the current context for the grid

Signals

colorChanged

Emitted when a color has been selected from the widget

hovered

Emitted when mouse hovers over widget

class qgis.gui.QgsColorSwatchGrid[source]

Bases: QWidget

__init__(scheme: QgsColorScheme | None, context: str | None = '', parent: QWidget | None = None)

Construct a new color swatch grid.

Parameters:
  • scheme (Optional[QgsColorScheme]) – QgsColorScheme for colors to show in grid

  • context (Optional[str] = '') – context string provided to color scheme

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

baseColor(self) QColor[source]

Gets the base color for the widget

Return type:

QColor

Returns:

base color which is passed to scheme for color generation

See also

setBaseColor()

signal colorChanged(color: QColor)[source]

Emitted when a color has been selected from the widget

Parameters:

color (QColor) – selected color

colors(self) List[Tuple[QColor, str]] | None[source]

Gets the list of colors shown in the grid

Return type:

Optional[List[Tuple[QColor, str]]]

Returns:

list of colors currently shown in the grid

context(self) str[source]

Gets the current context for the grid

Return type:

str

Returns:

context string which is passed to scheme for color generation

See also

setContext()

signal hovered[source]

Emitted when mouse hovers over widget

refreshColors(self)[source]

Reload colors from scheme and redraws the widget

setBaseColor(self, baseColor: QColor | Qt.GlobalColor)[source]

Sets the base color for the widget

Parameters:

baseColor (Union[QColor, Qt.GlobalColor]) – base color to pass to scheme for color generation

See also

baseColor()

setContext(self, context: str | None)[source]

Sets the current context for the grid

Parameters:

context (Optional[str]) – string which is passed to scheme for color generation

See also

context()