Class: QgsLegendPatchShape

class qgis.core.QgsLegendPatchShape

Bases: sip.wrapper

Constructor for a null QgsLegendPatchShape.

A null QgsLegendPatchShape indicates that the default legend patch shape should be used instead.

QgsLegendPatchShape(type: QgsSymbol.SymbolType, geometry: QgsGeometry, preserveAspectRatio: bool = True) Constructor for QgsLegendPatchShape.

The type argument specifies the symbol type associated with this patch.

The geometry argument gives the shape of the patch to render. See setGeometry() for further details on the geometry requirements.

If preserveAspectRatio is True, then the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

QgsLegendPatchShape(QgsLegendPatchShape)

Represents a patch shape for use in map legends.

New in version 3.14:

Methods

geometry

Returns the geometry for the patch shape.

isNull

Returns True if the patch shape is a null QgsLegendPatchShape, which indicates that the default legend patch shape should be used instead.

preserveAspectRatio

Returns True if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

readXml

Read settings from a DOM element.

setGeometry

Sets the geometry for the patch shape.

setPreserveAspectRatio

Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

setSymbolType

Sets the symbol type associated with this patch.

symbolType

Returns the symbol type associated with this patch.

toQPolygonF

Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for a symbol of the given type at the specified size (as geometry parts and rings).

writeXml

Write settings into a DOM element.

geometry(self) QgsGeometry

Returns the geometry for the patch shape.

See also

setGeometry()

Return type

QgsGeometry

isNull(self) bool

Returns True if the patch shape is a null QgsLegendPatchShape, which indicates that the default legend patch shape should be used instead.

Return type

bool

preserveAspectRatio(self) bool

Returns True if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

Return type

bool

readXml(self, element: QDomElement, context: QgsReadWriteContext)

Read settings from a DOM element.

See also

writeXml()

Parameters
setGeometry(self, geometry: QgsGeometry)

Sets the geometry for the patch shape.

The origin and size of the geometry is not important, as the legend renderer will automatically scale and transform the geometry to match the desired overall patch bounds.

Geometries for legend patches are rendered respecting the traditional “y values increase toward the top of the map” convention, as opposed to the standard computer graphics convention of “y values increase toward the bottom of the display”.

Warning

The geometry type should match the patch shape’s symbolType(), e.g. a fill symbol type should only have Polygon or MultiPolygon geometries set, while a line symbol type must have LineString or MultiLineString geometries.

See also

geometry()

Parameters

geometry (QgsGeometry) –

setPreserveAspectRatio(self, preserve: bool)

Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

The default behavior is to respect the geometry()’s aspect ratio.

Parameters

preserve (bool) –

setSymbolType(self, type: QgsSymbol.SymbolType)

Sets the symbol type associated with this patch.

See also

symbolType()

Parameters

type (QgsSymbol.SymbolType) –

symbolType(self) QgsSymbol.SymbolType

Returns the symbol type associated with this patch.

See also

setSymbolType()

Return type

QgsSymbol.SymbolType

toQPolygonF(self, type: QgsSymbol.SymbolType, size: QSizeF) object

Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for a symbol of the given type at the specified size (as geometry parts and rings).

Parameters
Return type

object

writeXml(self, element: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)

Write settings into a DOM element.

See also

readXml()

Parameters