Class: QgsColorSchemeList

An editable list of color swatches, taken from an associated QgsColorScheme.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorSchemeList

Base classes

QTreeView

QAbstractItemView

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

Methods

addColor

Adds a color to the list

copyColors

Copies colors from the list to the clipboard

exportColorsToGpl

Export colors to a GPL palette file from the list

importColorsFromGpl

Import colors from a GPL palette file to the list

isDirty

Returns whether the color scheme list has been modified

pasteColors

Pastes colors from clipboard to the list

removeSelection

Removes any selected colors from the list

saveColorsToScheme

Saves the current colors shown in the list back to a color scheme, if supported by the color scheme.

scheme

Returns the scheme currently selected in the list.

setScheme

Sets the color scheme to show in the list

showExportColorsDialog

Displays a file picker dialog allowing users to export colors from the list into a file.

showImportColorsDialog

Displays a file picker dialog allowing users to import colors into the list from a file.

Signals

colorSelected

Emitted when a color is selected from the list

class qgis.gui.QgsColorSchemeList[source]

Bases: QTreeView

__init__(parent: QWidget | None = None, scheme: QgsColorScheme | None = None, context: str | None = '', baseColor: QColor | Qt.GlobalColor = QColor())

Construct a new color swatch grid.

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

  • scheme (Optional[QgsColorScheme] = None) – QgsColorScheme for colors to show in the list

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

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

addColor(self, color: QColor | Qt.GlobalColor, label: str | None = '', allowDuplicate: bool = False)[source]

Adds a color to the list

Parameters:
  • color (Union[QColor, Qt.GlobalColor]) – color to add

  • label (Optional[str] = '') – optional label for color

  • allowDuplicate (bool = False) – set to True to allow duplicate colors to be added, ie colors which already exist in the list

signal colorSelected(color: QColor)[source]

Emitted when a color is selected from the list

Parameters:

color (QColor) – color selected

copyColors(self)[source]

Copies colors from the list to the clipboard

See also

pasteColors()

exportColorsToGpl(self, file: QFile) bool[source]

Export colors to a GPL palette file from the list

Parameters:

file (QFile) – destination file

Return type:

bool

importColorsFromGpl(self, file: QFile) bool[source]

Import colors from a GPL palette file to the list

Parameters:

file (QFile) – file to import

Return type:

bool

isDirty(self) bool[source]

Returns whether the color scheme list has been modified

Return type:

bool

Returns:

True if colors have been modified

pasteColors(self)[source]

Pastes colors from clipboard to the list

See also

copyColors()

removeSelection(self)[source]

Removes any selected colors from the list

saveColorsToScheme(self) bool[source]

Saves the current colors shown in the list back to a color scheme, if supported by the color scheme.

Note

this method is only effective if the color scheme is editable

Return type:

bool

scheme(self) QgsColorScheme | None[source]

Returns the scheme currently selected in the list.

See also

setScheme()

Return type:

Optional[QgsColorScheme]

setScheme(self, scheme: QgsColorScheme | None, context: str | None = '', baseColor: QColor | Qt.GlobalColor = QColor())[source]

Sets the color scheme to show in the list

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

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

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

See also

scheme()

showExportColorsDialog(self)[source]

Displays a file picker dialog allowing users to export colors from the list into a file.

showImportColorsDialog(self)[source]

Displays a file picker dialog allowing users to import colors into the list from a file.