Class: QgsLegendRenderer

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

Bases: sip.wrapper

Construct legend renderer. The ownership of legend model does not change

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.

Parameters
drawLegend(self, painter: QPainter)

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

Parameters

painter (QPainter) –

legendSize(self) → QSizeF

Find out preferred legend size set by the client. If null, the legend will be drawn with the minimum size

Return type

QSizeF

minimumSize(self) → QSizeF

Run the layout algorithm and determine the size required for legend

Return type

QSizeF

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

QgsLegendStyle.Style

setLegendSize(self, s: QSizeF)

Sets the preferred resulting legend size.

Parameters

s (QSizeF) –

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