QgsColorSwatchGrid class

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

Colors are taken from an associated QgsColorScheme.

Constructors, destructors, conversion operators

QgsColorSwatchGrid(QgsColorScheme* scheme, const QString& context = QString(), QWidget* parent = nullptr)
Construct a new color swatch grid.

Public functions

auto baseColor() const -> QColor
Gets the base color for the widget.
auto colors() -> QgsNamedColorList*
Gets the list of colors shown in the grid.
auto context() const -> QString
Gets the current context for the grid.
void setBaseColor(const QColor& baseColor)
Sets the base color for the widget.
void setContext(const QString& context)
Sets the current context for the grid.

Signals

void colorChanged(const QColor& color)
Emitted when a color has been selected from the widget.
void hovered()
Emitted when mouse hovers over widget.

Public slots

void refreshColors()
Reload colors from scheme and redraws the widget.

Function documentation

QgsColorSwatchGrid::QgsColorSwatchGrid(QgsColorScheme* scheme, const QString& context = QString(), QWidget* parent = nullptr)

Construct a new color swatch grid.

Parameters
scheme QgsColorScheme for colors to show in grid
context context string provided to color scheme
parent parent widget

QColor QgsColorSwatchGrid::baseColor() const

Gets the base color for the widget.

Returns base color which is passed to scheme for color generation

QgsNamedColorList* QgsColorSwatchGrid::colors()

Gets the list of colors shown in the grid.

Returns list of colors currently shown in the grid

QString QgsColorSwatchGrid::context() const

Gets the current context for the grid.

Returns context string which is passed to scheme for color generation

void QgsColorSwatchGrid::setBaseColor(const QColor& baseColor)

Sets the base color for the widget.

Parameters
baseColor base color to pass to scheme for color generation

void QgsColorSwatchGrid::setContext(const QString& context)

Sets the current context for the grid.

Parameters
context string which is passed to scheme for color generation

void QgsColorSwatchGrid::colorChanged(const QColor& color) signal

Emitted when a color has been selected from the widget.

Parameters
color selected color