Class: QgsLegendRenderer

class qgis.core.QgsLegendRenderer(legendModel: QgsLayerTreeModel, settings: QgsLegendSettings)

Bases: sip.wrapper

Constructor for QgsLegendRenderer. The ownership of the legend model is not changed, and the model must exist for the lifetime of this renderer.

QgsLegendRenderer(QgsLegendRenderer)

The QgsLegendRenderer class handles automatic layout and rendering of legend. The content is given by QgsLayerTreeModel instance. Various layout properties can be configured within QgsLegendRenderer.

All spacing and sizes are in millimeters.

New in version 2.6: Methods

drawLegend Draws the legend with given painter.
legendSize Returns the preferred legend size set by the client.
minimumSize Runs the layout algorithm and returns the minimum size required for the legend.
nodeLegendStyle Returns the style for the given node, within the specified model.
setLegendSize Sets the preferred resulting legend size.
setNodeLegendStyle Sets the style of a node.

Signals

Attributes

drawLegend(self, painter: QPainter)

Draws the legend with given painter. The legend will occupy the area reported in legendSize(). The painter should be scaled beforehand so that units correspond to millimeters.

drawLegend(self, context: QgsRenderContext) Draws the legend using a given render context. The legend will occupy the area reported in legendSize().

New in version 3.6.

legendSize(self) → QSizeF

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

minimumSize()

See also

setLegendSize()

minimumSize(self, renderContext: QgsRenderContext = None) → QSizeF

Runs the layout algorithm and returns the minimum size required for the legend.

See also

setLegendSize()

See also

legendSize()

nodeLegendStyle(node: QgsLayerTreeNode, model: QgsLayerTreeModel) → QgsLegendStyle.Style

Returns the style for the given node, within the specified model.

setLegendSize(self, s: QSizeF)

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

legendSize()

See also

minimumSize()

setNodeLegendStyle(node: QgsLayerTreeNode, style: QgsLegendStyle.Style)

Sets the style of a node.