Class: QgsDataDefinedSizeLegend

class qgis.core.QgsDataDefinedSizeLegend

Bases: sip.wrapper

Object that keeps configuration of appearance of marker symbol’s data-defined size in legend.

For example: the list of classes (size values), whether the classes should appear in separate legend nodes or whether to collapse them into one legend node.

New in version 3.0.

QgsDataDefinedSizeLegend() Constructor for QgsDataDefinedSizeLegend.

QgsDataDefinedSizeLegend(other: QgsDataDefinedSizeLegend) Copy constructor

Methods

classes

Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label

collapsedLegendImage

Returns output image that would be shown in the legend.

drawCollapsedLegend

Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of labels (in painter units).

font

Returns font used for rendering of labels - only valid for collapsed legend

legendSymbolList

Generates legend symbol items according to the configuration

legendType

Returns how the legend should be rendered

lineSymbol

Returns the line symbol that will be used to draw callout lines in legend.

readXml

Creates instance from given element and returns it (caller takes ownership).

setClasses

Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label

setFont

Sets font used for rendering of labels - only valid for collapsed legend

setLegendType

Sets how the legend should be rendered

setLineSymbol

Sets the line symbol that will be used to draw callout lines in legend.

setSizeScaleTransformer

Sets transformer for scaling of symbol sizes.

setSymbol

Sets marker symbol that will be used to draw markers in legend

setTextAlignment

Sets horizontal text alignment for rendering of labels - only valid for collapsed legend

setTextColor

Sets text color for rendering of labels - only valid for collapsed legend

setTitle

Sets title label for data-defined size legend

setVerticalAlignment

Sets vertical alignment of symbols - only valid for collapsed legend

sizeScaleTransformer

Returns transformer for scaling of symbol sizes.

symbol

Returns marker symbol that will be used to draw markers in legend

textAlignment

Returns horizontal text alignment for rendering of labels - only valid for collapsed legend

textColor

Returns text color for rendering of labels - only valid for collapsed legend

title

Returns title label for data-defined size legend

updateFromSymbolAndProperty

Updates the list of classes, source symbol and title label from given symbol and property

verticalAlignment

Returns vertical alignment of symbols - only valid for collapsed legend

writeXml

Writes configuration to the given XML element.

Attributes

AlignBottom

AlignCenter

LegendCollapsed

LegendSeparated

AlignBottom = 1
AlignCenter = 0
LegendCollapsed = 1
LegendSeparated = 0
class LegendType

Bases: int

class SizeClass(size: float, label: str)
class SizeClass(QgsDataDefinedSizeLegend.SizeClass)

Bases: sip.wrapper

label
size
class VerticalAlignment

Bases: int

classes(self) List[QgsDataDefinedSizeLegend.SizeClass]

Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label

Return type

List[QgsDataDefinedSizeLegend.SizeClass]

collapsedLegendImage(self, context: QgsRenderContext, backgroundColor: Union[QColor, Qt.GlobalColor, QGradient] = Qt.transparent, paddingMM: float = 1) QImage

Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.

Parameters
  • context (QgsRenderContext) –

  • backgroundColor (Union[QColor) –

  • paddingMM (float = 1) –

Return type

QImage

drawCollapsedLegend(self, context: QgsRenderContext) Tuple[QSizeF, float]

Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of labels (in painter units). If the painter in context is None, it only does size calculation without actual rendering. Does nothing if legend is not configured as collapsed.

Parameters

context (QgsRenderContext) –

Return type

Tuple[QSizeF, float]

font(self) QFont

Returns font used for rendering of labels - only valid for collapsed legend

Return type

QFont

legendSymbolList(self) List[QgsLegendSymbolItem]

Generates legend symbol items according to the configuration

Return type

List[QgsLegendSymbolItem]

legendType(self) QgsDataDefinedSizeLegend.LegendType

Returns how the legend should be rendered

Return type

QgsDataDefinedSizeLegend.LegendType

lineSymbol(self) QgsLineSymbol

Returns the line symbol that will be used to draw callout lines in legend.

See also

setLineSymbol()

New in version 3.14.

Return type

QgsLineSymbol

readXml(elem: QDomElement, context: QgsReadWriteContext) QgsDataDefinedSizeLegend

Creates instance from given element and returns it (caller takes ownership). Returns None on error.

Parameters
Return type

QgsDataDefinedSizeLegend

setClasses(self, classes: Iterable[QgsDataDefinedSizeLegend.SizeClass])

Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label

Parameters

classes (Iterable[QgsDataDefinedSizeLegend.SizeClass]) –

setFont(self, font: QFont)

Sets font used for rendering of labels - only valid for collapsed legend

Parameters

font (QFont) –

setLegendType(self, type: QgsDataDefinedSizeLegend.LegendType)

Sets how the legend should be rendered

Parameters

type (QgsDataDefinedSizeLegend.LegendType) –

setLineSymbol(self, symbol: QgsLineSymbol)

Sets the line symbol that will be used to draw callout lines in legend.

Ownership of symbol is transferred.

See also

lineSymbol()

New in version 3.14.

Parameters

symbol (QgsLineSymbol) –

setSizeScaleTransformer(self, transformer: QgsSizeScaleTransformer)

Sets transformer for scaling of symbol sizes. Takes ownership of the object. Accepts None to set no transformer.

Parameters

transformer (QgsSizeScaleTransformer) –

setSymbol(self, symbol: QgsMarkerSymbol)

Sets marker symbol that will be used to draw markers in legend

Parameters

symbol (QgsMarkerSymbol) –

setTextAlignment(self, flag: Qt.AlignmentFlag)

Sets horizontal text alignment for rendering of labels - only valid for collapsed legend

Parameters

flag (Qt.AlignmentFlag) –

setTextColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets text color for rendering of labels - only valid for collapsed legend

Parameters

color (Union[QColor) –

setTitle(self, title: str)

Sets title label for data-defined size legend

Parameters

title (str) –

setVerticalAlignment(self, vAlign: QgsDataDefinedSizeLegend.VerticalAlignment)

Sets vertical alignment of symbols - only valid for collapsed legend

Parameters

vAlign (QgsDataDefinedSizeLegend.VerticalAlignment) –

sizeScaleTransformer(self) QgsSizeScaleTransformer

Returns transformer for scaling of symbol sizes. Returns None if no transformer is defined.

Return type

QgsSizeScaleTransformer

symbol(self) QgsMarkerSymbol

Returns marker symbol that will be used to draw markers in legend

Return type

QgsMarkerSymbol

textAlignment(self) Qt.AlignmentFlag

Returns horizontal text alignment for rendering of labels - only valid for collapsed legend

Return type

Qt.AlignmentFlag

textColor(self) QColor

Returns text color for rendering of labels - only valid for collapsed legend

Return type

QColor

title(self) str

Returns title label for data-defined size legend

Return type

str

updateFromSymbolAndProperty(self, symbol: QgsMarkerSymbol, ddSize: QgsProperty)

Updates the list of classes, source symbol and title label from given symbol and property

Parameters
verticalAlignment(self) QgsDataDefinedSizeLegend.VerticalAlignment

Returns vertical alignment of symbols - only valid for collapsed legend

Return type

QgsDataDefinedSizeLegend.VerticalAlignment

writeXml(self, elem: QDomElement, context: QgsReadWriteContext)

Writes configuration to the given XML element.

Parameters