Class: QgsColorSwatchGridAction

A color swatch grid which can be embedded into a menu.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorSwatchGridAction

Base classes

QWidgetAction

QAction

QObject

Methods

baseColor

Gets the base color for the color grid

context

Gets the current context for the color grid

dismissOnColorSelection

Returns whether the parent menu will be dismissed after a color is selected from the action's color widget.

refreshColors

Reload colors from scheme and redraws the widget

setBaseColor

Sets the base color for the color grid

setContext

Sets the current context for the color grid

setDismissOnColorSelection

Sets whether the parent menu should be dismissed and closed when a color is selected from the action's color widget.

Signals

colorChanged

Emitted when a color has been selected from the widget

class qgis.gui.QgsColorSwatchGridAction[source]

Bases: QWidgetAction

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

Construct a new color swatch grid action.

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

  • menu (Optional[QMenu] = None) – parent menu

  • 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 color grid

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

context(self) str[source]

Gets the current context for the color grid

Return type:

str

Returns:

context string which is passed to scheme for color generation

See also

setContext()

dismissOnColorSelection(self) bool[source]

Returns whether the parent menu will be dismissed after a color is selected from the action’s color widget.

Return type:

bool

refreshColors(self)[source]

Reload colors from scheme and redraws the widget

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

Sets the base color for the color grid

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 color grid

Parameters:

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

See also

context()

setDismissOnColorSelection(self, dismiss: bool)[source]

Sets whether the parent menu should be dismissed and closed when a color is selected from the action’s color widget.

Parameters:

dismiss (bool) – set to True (default) to immediately close the menu when a color is selected from the widget. If set to False, the colorChanged signal will be emitted but the menu will stay open.