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. SeesetGeometry()
for further details on the geometry requirements.If
preserveAspectRatio
isTrue
, 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.
Methods
Returns the geometry for the patch shape.
Returns
True
if the patch shape is a nullQgsLegendPatchShape
, which indicates that the default legend patch shape should be used instead.Returns
True
if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.Read settings from a DOM
element
.Sets the
geometry
for the patch shape.Sets whether the patch shape should
preserve
its aspect ratio when it is resized to fit a desired legend patch size.Sets the symbol
type
associated with this patch.Returns the symbol type associated with this patch.
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 specifiedsize
(as geometry parts and rings).Write settings into a DOM
element
.- geometry(self) → QgsGeometry¶
Returns the geometry for the patch shape.
See also
- Return type
- isNull(self) → bool¶
Returns
True
if the patch shape is a nullQgsLegendPatchShape
, 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.See also
- Return type
bool
- readXml(self, element: QDomElement, context: QgsReadWriteContext)¶
Read settings from a DOM
element
.See also
- Parameters
element (QDomElement) –
context (QgsReadWriteContext) –
- 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
- 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.See also
- Parameters
preserve (bool) –
- setSymbolType(self, type: QgsSymbol.SymbolType)¶
Sets the symbol
type
associated with this patch.See also
- Parameters
type (QgsSymbol.SymbolType) –
- symbolType(self) → QgsSymbol.SymbolType¶
Returns the symbol type associated with this patch.
See also
- Return type
- 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 specifiedsize
(as geometry parts and rings).- Parameters
type (QgsSymbol.SymbolType) –
size (QSizeF) –
- Return type
object
- writeXml(self, element: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)¶
Write settings into a DOM
element
.See also
- Parameters
element (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –