Class: QgsLegendRenderer¶
Handles automatic layout and rendering of legends.
The content is given by QgsLayerTreeModel
instance. Various
layout properties can be configured within
QgsLegendRenderer
.
All spacing and sizes are in millimeters.
Methods
Draws the legend with given painter. |
|
Renders the legend in a json object. |
|
Returns the preferred legend size set by the client. |
|
Runs the layout algorithm and returns the minimum size required for the legend. |
|
Returns the filter proxy model used for filtering the legend model content during rendering. |
|
Sets the preferred resulting legend size. |
Static Methods
Returns the style for the given node, within the specified model. |
|
Sets the style of a node. |
- class qgis.core.QgsLegendRenderer[source]¶
Bases:
object
- __init__(legendModel: QgsLayerTreeModel | None, settings: QgsLegendSettings)
Constructor for QgsLegendRenderer. The ownership of the legend model is not changed, and the model must exist for the lifetime of this renderer.
- Parameters:
legendModel (Optional[QgsLayerTreeModel])
settings (QgsLegendSettings)
- drawLegend(self, painter: QPainter | None)[source]¶
Draws the legend with given
painter
. The legend will occupy the area reported inlegendSize()
. Thepainter
should be scaled beforehand so that units correspond to millimeters.Deprecated since version 3.40: Use the variant which accepts a
QgsRenderContext
instead.- Parameters:
painter (Optional[QPainter])
- drawLegend(self, context: QgsRenderContext)[source]
Draws the legend using a given render
context
. The legend will occupy the area reported inlegendSize()
.Added in version 3.6.
- Parameters:
context (
QgsRenderContext
)
- exportLegendToJson(self, context: QgsRenderContext) Dict[str, QJsonValue] [source]¶
Renders the legend in a
json
object.Added in version 3.8.
- Parameters:
context (QgsRenderContext)
- Return type:
Dict[str, QJsonValue]
- legendSize(self) QSizeF [source]¶
Returns the preferred legend size set by the client.
If the returned size is null, the legend will be drawn with the minimum possible size to fit its content.
See also
See also
- Return type:
QSizeF
- minimumSize(self, renderContext: QgsRenderContext | None = None) QSizeF [source]¶
Runs the layout algorithm and returns the minimum size required for the legend.
See also
See also
- Parameters:
renderContext (Optional[QgsRenderContext] = None)
- Return type:
QSizeF
- static nodeLegendStyle(node: QgsLayerTreeNode | None, model: QgsLayerTreeModel | None) Qgis.LegendComponent [source]¶
Returns the style for the given
node
, within the specifiedmodel
.See also
- Parameters:
node (Optional[QgsLayerTreeNode])
model (Optional[QgsLayerTreeModel])
- Return type:
- proxyModel(self) QgsLayerTreeFilterProxyModel | None [source]¶
Returns the filter proxy model used for filtering the legend model content during rendering.
Filters can be set on the proxy model to filter rendered legend content.
Added in version 3.40.
- Return type:
Optional[QgsLayerTreeFilterProxyModel]
- setLegendSize(self, s: QSizeF)[source]¶
Sets the preferred resulting legend size.
If the size is null, the legend will be drawn with the minimum possible size to fit its content.
See also
See also
- Parameters:
s (QSizeF)
- static setNodeLegendStyle(node: QgsLayerTreeNode | None, style: Qgis.LegendComponent)[source]¶
Sets the
style
of anode
.See also
- Parameters:
node (Optional[QgsLayerTreeNode])
style (Qgis.LegendComponent)