Class: QgsSymbolLegendNode

class qgis.core.QgsSymbolLegendNode

Bases: QgsLayerTreeModelLegendNode

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

Added in version 2.6.

QgsSymbolLegendNode(nodeLayer: Optional[QgsLayerTreeLayer], item: QgsLegendSymbolItem, parent: Optional[QObject] = None) Constructor for QgsSymbolLegendNode.

Parameters:
MAXIMUM_SIZE = -1.0
MINIMUM_SIZE = -1.0
childEvent(self, a0: QChildEvent | None)
connectNotify(self, signal: QMetaMethod)
createTemporaryRenderContext(self) QgsRenderContext | None

Returns a temporary context or None if legendMapViewData are not valid

customEvent(self, a0: QEvent | None)
customSymbol(self) QgsSymbol | None

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]

data(self, role: int) Any
Parameters:

role (int)

Return type:

Any

disconnectNotify(self, signal: QMetaMethod)
drawSymbol(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext | None, itemHeight: float) QSizeF
Parameters:
Return type:

QSizeF

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

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

exportSymbolToJson(self, settings: QgsLegendSettings, context: QgsRenderContext) Dict[str, QJsonValue]
Parameters:
Return type:

Dict[str, QJsonValue]

flags(self) Qt.ItemFlags
Return type:

Qt.ItemFlags

iconSize(self) QSize

Added in version 2.10.

Return type:

QSize

invalidateMapBasedData(self)
isScaleOK(self, scale: float) bool
Parameters:

scale (float)

Return type:

bool

isSignalConnected(self, signal: QMetaMethod) bool
minimumIconSize(self) QSize

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.

Added in version 2.10.

minimumIconSize(self, context: Optional[QgsRenderContext]) -> QSize 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().

Added in version 2.18.

Return type:

QSize

patchShape(self) QgsLegendPatchShape

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

See also

setPatchShape()

Added in version 3.14.

Return type:

QgsLegendPatchShape

receivers(self, signal: PYQT_SIGNAL) int
sender(self) QObject | None
senderSignalIndex(self) int
setCustomSymbol(self, symbol: QgsSymbol | None)

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])

setData(self, value: Any, role: int) bool
Parameters:
  • value (Any)

  • role (int)

Return type:

bool

setEmbeddedInParent(self, embedded: bool)
Parameters:

embedded (bool)

setIconSize(self, sz: QSize)

Set the icon size

Added in version 2.10.

Parameters:

sz (QSize)

setPatchShape(self, shape: QgsLegendPatchShape)

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)

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()

Added in version 2.14.

setTextOnSymbolLabel(self, label: str | None)

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)

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

Added in version 3.2.

Parameters:

format (QgsTextFormat)

setUserLabel(self, userLabel: str | None)
Parameters:

userLabel (Optional[str])

symbol(self) QgsSymbol | None

Returns the symbol used by the legend node.

See also

setSymbol()

Added in version 2.14.

Return type:

Optional[QgsSymbol]

symbolLabel(self) str

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

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

Added in version 3.2.

Return type:

str

textOnSymbolTextFormat(self) QgsTextFormat

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

Added in version 3.2.

Return type:

QgsTextFormat

timerEvent(self, a0: QTimerEvent | None)