Class: QgsColorScheme

class qgis.core.QgsColorScheme

Bases: sip.wrapper

Abstract base class for color schemes

A color scheme for display in QgsColorButton. Color schemes return lists of colors with an optional associated color name. The colors returned can be generated using an optional base color.

QgsColorScheme() Constructor for QgsColorScheme.

QgsColorScheme(QgsColorScheme)

Methods

clone

Clones a color scheme

fetchColors

Gets a list of colors from the scheme.

flags

Returns the current flags for the color scheme.

isEditable

Returns whether the color scheme is editable

schemeName

Gets the name for the color scheme

setColors

Sets the colors for the scheme.

Attributes

ShowInAllContexts

ShowInColorButtonMenu

ShowInColorDialog

class SchemeFlag

Bases: int

class SchemeFlags
class SchemeFlags(Union[QgsColorScheme.SchemeFlags, QgsColorScheme.SchemeFlag])
class SchemeFlags(QgsColorScheme.SchemeFlags)

Bases: sip.wrapper

ShowInAllContexts = 3
ShowInColorButtonMenu = 2
ShowInColorDialog = 1
clone(self) QgsColorScheme

Clones a color scheme

Return type:

QgsColorScheme

Returns:

copy of color scheme

fetchColors(self, context: str = '', baseColor: QColor | Qt.GlobalColor | QGradient = QColor()) List[Tuple[QColor, str]]

Gets a list of colors from the scheme. The colors can optionally be generated using the supplied context and base color.

Parameters:
  • context (str = '') – string specifying an optional context for the returned colors. For instance, a “recent colors” scheme may filter returned colors by context so that colors used only in a “composer” context are returned.

  • baseColor (Union[QColor) – base color for the scheme’s colors. Some color schemes may take advantage of this to filter or modify their returned colors to colors related to the base color.

Return type:

List[Tuple[QColor, str]]

Returns:

a list of QPairs of color and color name

flags(self) QgsColorScheme.SchemeFlags

Returns the current flags for the color scheme.

Return type:

QgsColorScheme.SchemeFlags

Returns:

current flags

isEditable(self) bool

Returns whether the color scheme is editable

Return type:

bool

Returns:

True if scheme is editable

See also

setColors()

schemeName(self) str

Gets the name for the color scheme

Return type:

str

Returns:

color scheme name

setColors(self, colors: Iterable[Tuple[QColor | Qt.GlobalColor | QGradient, str]], context: str = '', baseColor: QColor | Qt.GlobalColor | QGradient = QColor()) bool

Sets the colors for the scheme. This method is only valid for editable color schemes.

Parameters:
  • colors (Iterable[Tuple[Union[QColor) – list of colors for the scheme

  • context (str = '') – to set colors for

  • baseColor (Union[QColor) – base color to set colors for

Return type:

bool

Returns:

True if colors were set successfully

See also

isEditable()