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¶
Base classes¶
An abstract interface for legend items returned from |
|
Methods
Create an expression context scope containing symbol related variables. |
|
Returns the node's custom symbol. |
|
Evaluates and returns the text label of the current node |
|
Calculates the minimum icon size to prevent cropping. |
|
Returns the symbol patch shape to use when rendering the legend node symbol. |
|
Sets the node's custom symbol. |
|
Set the icon size |
|
Sets the symbol patch shape to use when rendering the legend node symbol. |
|
Sets the symbol to be used by the legend node. |
|
Sets label of text to be shown on top of the symbol. |
|
Sets format of text to be shown on top of the symbol. |
|
Returns the symbol used by the legend node. |
|
Label of the symbol, user defined label will be used, otherwise will default to the label made by QGIS. |
|
Returns label of text to be shown on top of the symbol. |
|
Returns text format of the label to be shown on top of the symbol. |
Attributes
- 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 defaultsymbol()
.See also
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()) – extraQgsExpressionContext
to use for evaluating the expressionlabel (Optional[str] = '') – text to evaluate instead of the layer layertree string
Added in version 3.10.
- Return type:
str
- 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
Added in version 3.14.
- Return type:
- 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 defaultsymbol()
.Ownership of
symbol
is transferred.See also
Added in version 3.14.
- Parameters:
symbol (Optional[QgsSymbol])
- setPatchShape(self, shape: QgsLegendPatchShape)[source]¶
Sets the symbol patch
shape
to use when rendering the legend node symbol.See also
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
- 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
- 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: