Class: QgsColorScheme

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.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), fetchColors(), schemeName()

Class Hierarchy

Inheritance diagram of qgis.core.QgsColorScheme

Subclasses

QgsCustomColorScheme

A color scheme which contains custom colors set through QGIS app options dialog.

QgsGplColorScheme

A color scheme which stores its colors in a gpl palette file.

QgsPresetSchemeColorRamp

A scheme based color ramp consisting of a list of predefined colors.

QgsProjectColorScheme

A color scheme which contains project specific colors set through project properties dialog.

QgsRecentColorScheme

A color scheme which contains the most recently used colors.

Abstract Methods

clone

Clones a color scheme

fetchColors

Gets a list of colors from the scheme.

schemeName

Gets the name for the color scheme

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsColorScheme. See the FAQ for more details.

flags

Returns the current flags for the color scheme.

isEditable

Returns whether the color scheme is editable

setColors

Sets the colors for the scheme.

Attributes

ShowInAllContexts

ShowInColorButtonMenu

ShowInColorDialog

class qgis.core.QgsColorScheme[source]

Bases: object

class SchemeFlag

Bases: int

class SchemeFlags
class SchemeFlags(f: QgsColorScheme.SchemeFlags | QgsColorScheme.SchemeFlag)
class SchemeFlags(a0: QgsColorScheme.SchemeFlags)

Bases: object

ShowInAllContexts = 3
ShowInColorButtonMenu = 2
ShowInColorDialog = 1
abstract clone(self) QgsColorScheme | None[source]

Clones a color scheme

Return type:

Optional[QgsColorScheme]

Returns:

copy of color scheme

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

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

Parameters:
  • context (Optional[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, Qt.GlobalColor] = 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

virtual flags(self) QgsColorScheme.SchemeFlags[source]

Returns the current flags for the color scheme.

Return type:

QgsColorScheme.SchemeFlags

Returns:

current flags

virtual isEditable(self) bool[source]

Returns whether the color scheme is editable

Return type:

bool

Returns:

True if scheme is editable

See also

setColors()

abstract schemeName(self) str[source]

Gets the name for the color scheme

Return type:

str

Returns:

color scheme name

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

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

Parameters:
  • colors (Iterable[Tuple[Union[QColor, Qt.GlobalColor], Optional[str]]]) – list of colors for the scheme

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

  • baseColor (Union[QColor, Qt.GlobalColor] = QColor()) – base color to set colors for

Return type:

bool

Returns:

True if colors were set successfully

See also

isEditable()