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 byQgsLayerTreeModel
instance. Various layout properties can be configured withinQgsLegendRenderer
.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 style for the given
node
, within the specifiedmodel
.Sets the preferred resulting legend size.
Sets the
style
of anode
.- drawLegend(self, painter: QPainter)¶
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 Use: the variant which accepts a
QgsRenderContext
instead.drawLegend(self, context:
QgsRenderContext
) Draws the legend using a given rendercontext
. The legend will occupy the area reported inlegendSize()
.New in version 3.6.
- Parameters
painter (QPainter) –
- exportLegendToJson(self, context: QgsRenderContext) → Dict[str, QJsonValue]¶
Renders the legend in a
json
object.New in version 3.8.
- Parameters
context (QgsRenderContext) –
- Return type
Dict[str, QJsonValue]
- 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
See also
- Return type
QSizeF
- minimumSize(self, renderContext: QgsRenderContext = None) → QSizeF¶
Runs the layout algorithm and returns the minimum size required for the legend.
See also
See also
- Parameters
renderContext (
QgsRenderContext
= None) –- Return type
QSizeF
- nodeLegendStyle(node: QgsLayerTreeNode, model: QgsLayerTreeModel) → QgsLegendStyle.Style¶
Returns the style for the given
node
, within the specifiedmodel
.See also
- Parameters
node (QgsLayerTreeNode) –
model (QgsLayerTreeModel) –
- Return type
- 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
See also
- Parameters
s (QSizeF) –
- setNodeLegendStyle(node: QgsLayerTreeNode, style: QgsLegendStyle.Style)¶
Sets the
style
of anode
.See also
- Parameters
node (QgsLayerTreeNode) –
style (QgsLegendStyle.Style) –