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.

indent

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

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.

setIndent

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

setMargin

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

setTextFormat

Sets the text format used for rendering this legend 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.

textFormat

Returns the text format used for rendering this legend component.

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

Deprecated since version use: textFormat() instead

Return type:

QFont

indent(self) float

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

See also

indent()

New in version 3.22.

Return type:

float

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

Deprecated since version use: setTextFormat() instead

Parameters:

font (QFont) –

setIndent(self, indent: float)

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

See also

indent()

New in version 3.22.

Parameters:

indent (float) –

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:
setTextFormat(self, format: QgsTextFormat)

Sets the text format used for rendering this legend component.

See also

textFormat()

New in version 3.30.

Parameters:

format (QgsTextFormat) –

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

textFormat(self) QgsTextFormat

Returns the text format used for rendering this legend component.

See also

setTextFormat()

New in version 3.30.

Return type:

QgsTextFormat

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