Class: QgsSymbolLegendNode

Implementation of legend node interface for displaying preview of vector symbols and their labels and allowing interaction with the symbol / renderer.

Class Hierarchy

Inheritance diagram of qgis.core.QgsSymbolLegendNode

Base classes

QgsLayerTreeModelLegendNode

An abstract interface for legend items returned from QgsMapLayerLegend implementation.

QObject

Methods

createSymbolScope

Create an expression context scope containing symbol related variables.

customSymbol

Returns the node's custom symbol.

evaluateLabel

Evaluates and returns the text label of the current node

iconSize

minimumIconSize

Calculates the minimum icon size to prevent cropping.

patchShape

Returns the symbol patch shape to use when rendering the legend node symbol.

setCustomSymbol

Sets the node's custom symbol.

setIconSize

Set the icon size

setPatchShape

Sets the symbol patch shape to use when rendering the legend node symbol.

setSymbol

Sets the symbol to be used by the legend node.

setTextOnSymbolLabel

Sets label of text to be shown on top of the symbol.

setTextOnSymbolTextFormat

Sets format of text to be shown on top of the symbol.

symbol

Returns the symbol used by the legend node.

symbolLabel

Label of the symbol, user defined label will be used, otherwise will default to the label made by QGIS.

textOnSymbolLabel

Returns label of text to be shown on top of the symbol.

textOnSymbolTextFormat

Returns text format of the label to be shown on top of the symbol.

Attributes

MAXIMUM_SIZE

MINIMUM_SIZE

class qgis.core.QgsSymbolLegendNode[source]

Bases: QgsLayerTreeModelLegendNode

__init__(nodeLayer: QgsLayerTreeLayer | None, item: QgsLegendSymbolItem, parent: QObject | None = None)

Constructor for QgsSymbolLegendNode.

Parameters:
  • nodeLayer (Optional[QgsLayerTreeLayer]) – layer node

  • item (QgsLegendSymbolItem) – the legend symbol item

  • parent (Optional[QObject] = None) – attach a parent QObject to the legend node.

MAXIMUM_SIZE = -1.0
MINIMUM_SIZE = -1.0
createSymbolScope(self) QgsExpressionContextScope | None[source]

Create an expression context scope containing symbol related variables.

The caller takes ownership of the returned object.

Added in version 3.36.

Return type:

Optional[QgsExpressionContextScope]

customSymbol(self) QgsSymbol | None[source]

Returns the node’s custom symbol.

If a non-None value is returned, then this symbol will be used for rendering the legend node instead of the default symbol().

Added in version 3.14.

Return type:

Optional[QgsSymbol]

evaluateLabel(self, context: QgsExpressionContext = QgsExpressionContext(), label: str | None = '') str[source]

Evaluates and returns the text label of the current node

Parameters:
  • context (QgsExpressionContext = QgsExpressionContext()) – extra QgsExpressionContext to use for evaluating the expression

  • label (Optional[str] = '') – text to evaluate instead of the layer layertree string

Added in version 3.10.

Return type:

str

iconSize(self) QSize[source]
Return type:

QSize

minimumIconSize(self) QSize[source]

Calculates the minimum icon size to prevent cropping. When evaluating the size for multiple icons it is more efficient to create a single render context in advance and use the variant which accepts a QgsRenderContext argument.

Return type:

QSize

minimumIconSize(self, context: QgsRenderContext | None) QSize[source]

Calculates the minimum icon size to prevent cropping. When evaluating the size for multiple icons it is more efficient to create a single render context in advance and call this method instead of minimumIconSize().

Parameters:

context (Optional[QgsRenderContext])

Return type:

QSize

patchShape(self) QgsLegendPatchShape[source]

Returns the symbol patch shape to use when rendering the legend node symbol.

See also

setPatchShape()

Added in version 3.14.

Return type:

QgsLegendPatchShape

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

Sets the node’s custom symbol.

If a non-None value is set, then this symbol will be used for rendering the legend node instead of the default symbol().

Ownership of symbol is transferred.

See also

customSymbol()

Added in version 3.14.

Parameters:

symbol (Optional[QgsSymbol])

setIconSize(self, sz: QSize)[source]

Set the icon size

Parameters:

sz (QSize)

setPatchShape(self, shape: QgsLegendPatchShape)[source]

Sets the symbol patch shape to use when rendering the legend node symbol.

See also

patchShape()

Added in version 3.14.

Parameters:

shape (QgsLegendPatchShape)

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

Sets the symbol to be used by the legend node. The symbol change is also propagated to the associated vector layer’s renderer.

Parameters:

symbol (Optional[QgsSymbol]) – new symbol for node. Ownership is transferred.

See also

symbol()

setTextOnSymbolLabel(self, label: str | None)[source]

Sets label of text to be shown on top of the symbol.

Added in version 3.2.

Parameters:

label (Optional[str])

setTextOnSymbolTextFormat(self, format: QgsTextFormat)[source]

Sets format of text to be shown on top of the symbol.

Added in version 3.2.

Parameters:

format (QgsTextFormat)

symbol(self) QgsSymbol | None[source]

Returns the symbol used by the legend node.

See also

setSymbol()

Return type:

Optional[QgsSymbol]

symbolLabel(self) str[source]

Label of the symbol, user defined label will be used, otherwise will default to the label made by QGIS.

Added in version 3.10.

Return type:

str

textOnSymbolLabel(self) str[source]

Returns label of text to be shown on top of the symbol.

Added in version 3.2.

Return type:

str

textOnSymbolTextFormat(self) QgsTextFormat[source]

Returns text format of the label to be shown on top of the symbol.

Added in version 3.2.

Return type:

QgsTextFormat