Class: QgsLegendStyle

class qgis.core.QgsLegendStyle

Bases: sip.wrapper

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

Methods

alignment

Returns the alignment for the legend component.

font

Returns the font used for rendering this legend component.

margin

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

readXml

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

setAlignment

Sets the alignment for the legend component.

setFont

Sets the font used for rendering this legend component.

setMargin

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

styleFromName

Returns the style from name string.

styleLabel

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

styleName

Returns the name for a style component as a string.

writeXml

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

Attributes

Bottom

Group

Hidden

Left

Right

Subgroup

Symbol

SymbolLabel

Title

Top

Undefined

Bottom = 1
Group = 3
Hidden = 1
Left = 2
Right = 3
class Side

Bases: int

class Style

Bases: int

Subgroup = 4
Symbol = 5
SymbolLabel = 6
Title = 2
Top = 0
Undefined = 0
alignment(self) → Qt.Alignment

Returns the alignment for the legend component.

See also

setAlignment()

New in version 3.10.

Return type

Qt.Alignment

font(self) → QFont

Returns the font used for rendering this legend component.

See also

setFont()

Return type

QFont

margin(self, side: QgsLegendStyle.Side) → float

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())

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

See also

writeXml()

Parameters
  • elem (QDomElement) –

  • doc (QDomDocument) –

  • context (QgsReadWriteContext = QgsReadWriteContext()) –

setAlignment(self, alignment: Union[Qt.Alignment, Qt.AlignmentFlag])

Sets the alignment for the legend component.

See also

alignment()

New in version 3.10.

Parameters

alignment (Union[Qt.Alignment) –

setFont(self, font: QFont)

Sets the font used for rendering this legend component.

See also

font()

Parameters

font (QFont) –

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

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
styleFromName(styleName: str)QgsLegendStyle.Style

Returns the style from name string.

See also

styleName()

Parameters

styleName (str) –

Return type

QgsLegendStyle.Style

styleLabel(s: QgsLegendStyle.Style) → str

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

See also

styleName()

Parameters

s (QgsLegendStyle.Style) –

Return type

str

styleName(s: QgsLegendStyle.Style) → str

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 (QgsLegendStyle.Style) –

Return type

str

writeXml(self, name: str, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext())

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

See also

readXml()

Parameters
  • name (str) –

  • elem (QDomElement) –

  • doc (QDomDocument) –

  • context (QgsReadWriteContext = QgsReadWriteContext()) –