Class: QgsSymbolButton

A button for creating and modifying QgsSymbol settings.

The button shows a preview icon for the current symbol, and will open a detailed symbol editor dialog (or panel widget) when clicked.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsSymbolButton

Base classes

QToolButton

QAbstractButton

QWidget

QObject

QPaintDevice

Methods

copyColor

Copies the current symbol color to the clipboard.

copySymbol

Copies the current symbol to the clipboard.

defaultSymbol

Returns the default symbol for the button, which is shown in the button's drop-down menu for the "default symbol" option.

dialogTitle

Returns the title for the symbol settings dialog window.

isNull

Returns True if the current symbol is null.

layer

Returns the layer associated with the widget.

mapCanvas

Returns the map canvas associated with the widget.

messageBar

Returns the message bar associated with the widget.

pasteColor

Pastes a color from the clipboard to the symbol.

pasteSymbol

Pastes a symbol from the clipboard.

registerExpressionContextGenerator

Register an expression context generator class that will be used to retrieve an expression context for the button when required.

setColor

Sets the current color for the symbol.

setDefaultSymbol

Sets the default symbol for the button, which is shown in the button's drop-down menu for the "default symbol" option.

setDialogTitle

Sets the title for the symbol settings dialog window.

setLayer

Sets a layer to associate with the widget.

setMapCanvas

Sets a map canvas to associate with the widget.

setMessageBar

Sets the message bar associated with the widget.

setShowNull

Sets whether a set to null (clear) option is shown in the button's drop-down menu.

setSymbol

Sets the symbol for the button.

setSymbolType

Sets the symbol type which the button requires.

setToDefaultSymbol

Sets symbol to the button's default symbol, if set.

setToNull

Sets symbol to to null.

showNull

Returns whether the set to null (clear) option is shown in the button's drop-down menu.

symbol

Returns the current symbol defined by the button.

symbolType

Returns the symbol type which the button requires.

Signals

changed

Emitted when the symbol's settings are changed.

class qgis.gui.QgsSymbolButton[source]

Bases: QToolButton

__init__(parent: QWidget | None = None, dialogTitle: str | None = '')

Construct a new symbol button. Use dialogTitle string to define the title to show in the symbol settings dialog.

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

  • dialogTitle (Optional[str] = '')

signal changed[source]

Emitted when the symbol’s settings are changed.

See also

symbol()

See also

setSymbol()

copyColor(self)[source]

Copies the current symbol color to the clipboard.

See also

pasteColor()

copySymbol(self)[source]

Copies the current symbol to the clipboard.

See also

pasteSymbol()

defaultSymbol(self) QgsSymbol | None[source]

Returns the default symbol for the button, which is shown in the button’s drop-down menu for the “default symbol” option.

Return type:

Optional[QgsSymbol]

Returns:

default symbol for the button. Returns None if the default symbol option is disabled.

Added in version 3.30.

dialogTitle(self) str[source]

Returns the title for the symbol settings dialog window.

See also

setDialogTitle()

Return type:

str

isNull(self) bool[source]

Returns True if the current symbol is null.

See also

setShowNull()

See also

showNull()

Added in version 3.26.

Return type:

bool

layer(self) QgsVectorLayer | None[source]

Returns the layer associated with the widget.

See also

setLayer()

Return type:

Optional[QgsVectorLayer]

mapCanvas(self) QgsMapCanvas | None[source]

Returns the map canvas associated with the widget.

See also

setMapCanvas()

Return type:

Optional[QgsMapCanvas]

messageBar(self) QgsMessageBar | None[source]

Returns the message bar associated with the widget.

See also

setMessageBar()

Added in version 3.6.

Return type:

Optional[QgsMessageBar]

pasteColor(self)[source]

Pastes a color from the clipboard to the symbol. If clipboard does not contain a valid color or string representation of a color, then no change is applied.

See also

copyColor()

pasteSymbol(self)[source]

Pastes a symbol from the clipboard. If clipboard does not contain a valid symbol then no change is applied.

See also

copySymbol()

registerExpressionContextGenerator(self, generator: QgsExpressionContextGenerator | None)[source]

Register an expression context generator class that will be used to retrieve an expression context for the button when required.

Parameters:

generator (Optional[QgsExpressionContextGenerator])

setColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the current color for the symbol. Will emit a changed() signal if the color is different to the previous symbol color.

Parameters:

color (Union[QColor, Qt.GlobalColor])

setDefaultSymbol(self, symbol: QgsSymbol | None)[source]

Sets the default symbol for the button, which is shown in the button’s drop-down menu for the “default symbol” option.

Parameters:

symbol (Optional[QgsSymbol]) – default symbol for the button. Set to None to disable the default symbol option. Ownership of symbol is transferred to the button.

See also

defaultSymbol()

Added in version 3.30.

setDialogTitle(self, title: str | None)[source]

Sets the title for the symbol settings dialog window.

See also

dialogTitle()

Parameters:

title (Optional[str])

setLayer(self, layer: QgsVectorLayer | None)[source]

Sets a layer to associate with the widget. This allows the widget to setup layer related settings within the symbol settings dialog, such as correctly populating data defined override buttons.

See also

layer()

Parameters:

layer (Optional[QgsVectorLayer])

setMapCanvas(self, canvas: QgsMapCanvas | None)[source]

Sets a map canvas to associate with the widget. This allows the widget to fetch current settings from the map canvas, such as current scale.

See also

mapCanvas()

Parameters:

canvas (Optional[QgsMapCanvas])

setMessageBar(self, bar: QgsMessageBar | None)[source]

Sets the message bar associated with the widget. This allows the widget to push feedback messages to the appropriate message bar.

See also

messageBar()

Added in version 3.6.

Parameters:

bar (Optional[QgsMessageBar])

setShowNull(self, showNull: bool)[source]

Sets whether a set to null (clear) option is shown in the button’s drop-down menu.

Parameters:

showNull (bool) – set to True to show a null option

See also

showNull()

See also

isNull()

Added in version 3.26.

setSymbol(self, symbol: QgsSymbol | None)[source]

Sets the symbol for the button. Ownership of symbol is transferred to the button.

See also

symbol()

See also

changed()

Parameters:

symbol (Optional[QgsSymbol])

setSymbolType(self, type: Qgis.SymbolType)[source]

Sets the symbol type which the button requires. If the type differs from the current symbol type, the symbol will be reset to a default symbol style of the new type.

See also

symbolType()

Parameters:

type (Qgis.SymbolType)

setToDefaultSymbol(self)[source]

Sets symbol to the button’s default symbol, if set.

See also

defaultSymbol()

See also

setToNull()

Added in version 3.30.

setToNull(self)[source]

Sets symbol to to null.

See also

setShowNull()

See also

showNull()

Added in version 3.26.

showNull(self) bool[source]

Returns whether the set to null (clear) option is shown in the button’s drop-down menu.

See also

setShowNull()

See also

isNull()

Added in version 3.26.

Return type:

bool

symbol(self) QgsSymbol | None[source]

Returns the current symbol defined by the button.

See also

setSymbol()

See also

changed()

Return type:

Optional[QgsSymbol]

symbolType(self) Qgis.SymbolType[source]

Returns the symbol type which the button requires.

See also

setSymbolType()

Return type:

Qgis.SymbolType