Class: QgsLegendStyle

Contains detailed styling information relating to how a layout legend should be rendered.

class qgis.core.QgsLegendStyle[source]

Bases: object

Bottom = 1
Left = 2
Right = 3
class Side

Bases: int

Style

alias of LegendComponent

Top = 0
alignment(self) Qt.Alignment[source]

Returns the alignment for the legend component.

See also

setAlignment()

Added in version 3.10.

Return type:

Qt.Alignment

font(self) QFont[source]

Returns the font used for rendering this legend component.

See also

setFont()

Deprecated since version 3.40: Use textFormat() instead.

Return type:

QFont

indent(self) float[source]

Returns the indent (in mm) of a group or subgroup.

See also

indent()

Added in version 3.22.

Return type:

float

margin(self, side: QgsLegendStyle.Side) float[source]

Returns the margin (in mm) for the specified side of the component.

Note

Not all legend components respect all margin side settings!

See also

setMargin()

Parameters:

side (QgsLegendStyle.Side)

Return type:

float

readXml(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext())[source]

Reads the component’s style definition from an XML element.

See also

writeXml()

Parameters:
setAlignment(self, alignment: Qt.Alignment | Qt.AlignmentFlag)[source]

Sets the alignment for the legend component.

See also

alignment()

Added in version 3.10.

Parameters:

alignment (Union[Qt.Alignment, Qt.AlignmentFlag])

setFont(self, font: QFont)[source]

Sets the font used for rendering this legend component.

See also

font()

Deprecated since version 3.40: Use setTextFormat() instead.

Parameters:

font (QFont)

setIndent(self, indent: float)[source]

Sets the indent (in mm) of a group or subgroup.

See also

indent()

Added in version 3.22.

Parameters:

indent (float)

setMargin(self, side: QgsLegendStyle.Side, margin: float)[source]

Sets the margin (in mm) for the specified side of the component.

Note

Not all legend components respect all margin side settings!

See also

margin()

setMargin(self, margin: float) Sets all margin sides to the same margin size (in mm).

See also

margin()

Parameters:
setTextFormat(self, format: QgsTextFormat)[source]

Sets the text format used for rendering this legend component.

See also

textFormat()

Added in version 3.30.

Parameters:

format (QgsTextFormat)

static styleFromName(styleName: str | None) Qgis.LegendComponent[source]

Returns the style from name string.

See also

styleName()

Parameters:

styleName (Optional[str])

Return type:

Qgis.LegendComponent

static styleLabel(s: Qgis.LegendComponent) str[source]

Returns a translated string representing a style component, for use in UI.

See also

styleName()

Parameters:

s (Qgis.LegendComponent)

Return type:

str

static styleName(s: Qgis.LegendComponent) str[source]

Returns the name for a style component as a string.

This is a non-localised version, for internal use.

See also

styleFromName()

See also

styleLabel()

Parameters:

s (Qgis.LegendComponent)

Return type:

str

textFormat(self) QgsTextFormat

Returns the text format used for rendering this legend component.

See also

setTextFormat()

Added in version 3.30.

Return type:

QgsTextFormat

updateDataDefinedProperties(self, context: QgsRenderContext)[source]

Updates any data-defined properties in the style, using the specified render context.

Added in version 3.42.

Parameters:

context (QgsRenderContext)

writeXml(self, name: str | None, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext())[source]

Writes the component’s style definition to an XML element.

See also

readXml()

Parameters:
  • name (Optional[str])

  • elem (QDomElement)

  • doc (QDomDocument)

  • context (QgsReadWriteContext = QgsReadWriteContext())