Class: QgsSymbolLayer

class qgis.core.QgsSymbolLayer(type: Qgis.SymbolType, locked: bool = False)

Bases: sip.wrapper

Constructor for QgsSymbolLayer.

Parameters:
  • type – specifies the associated symbol type

  • locked

    if True, then symbol layer colors will be locked and will ignore any symbol-level color changes.

    Enums

    Property

    Bases: enum.IntEnum

    Methods

    canCauseArtifactsBetweenAdjacentTiles

    Returns True if the symbol layer rendering can cause visible artifacts across a single feature when the feature is rendered as a series of adjacent map tiles each containing a portion of the feature's geometry.

    clone

    Shall be reimplemented by subclasses to create a deep copy of the instance.

    color

    Returns the "representative" color of the symbol layer.

    copyDataDefinedProperties

    Copies all data defined properties of this layer to another symbol layer.

    copyPaintEffect

    Copies paint effect of this layer to another symbol layer

    dataDefinedProperties

    Returns a reference to the symbol layer's property collection, used for data defined overrides.

    drawPreviewIcon

    param context:

    dxfAngle

    Gets angle

    dxfBrushColor

    Gets brush/fill color

    dxfBrushStyle

    Gets brush/fill style

    dxfColor

    Gets color

    dxfCustomDashPattern

    Gets dash pattern

    dxfOffset

    Gets offset

    dxfPenStyle

    Gets pen style

    dxfSize

    Gets marker size

    dxfWidth

    Gets line width

    enabled

    Returns True if symbol layer is enabled and will be drawn.

    estimateMaxBleed

    Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when drawn in the specified /a context.

    fillColor

    Returns the fill color for the symbol layer.

    flags

    Returns flags which control the symbol layer's behavior.

    hasDataDefinedProperties

    Returns True if the symbol layer (or any of its sub-symbols) contains data defined properties.

    id

    Returns symbol layer identifier This id is unique in the whole project

    installMasks

    When rendering, install masks on context painter if recursive is True masks are installed recursively for all children symbol layers

    isCompatibleWithSymbol

    Returns if the layer can be used below the specified symbol

    isLocked

    Returns True if the symbol layer colors are locked and the layer will ignore any symbol-level color changes.

    layerType

    Returns a string that represents this layer type.

    mapUnitScale

    rtype:

    QgsMapUnitScale

    masks

    Returns masks defined by this symbol layer.

    ogrFeatureStyle

    param mmScaleFactor:

    outputUnit

    Returns the units to use for sizes and widths within the symbol layer.

    paintEffect

    Returns the current paint effect for the layer.

    prepareExpressions

    Prepares all data defined property expressions for evaluation.

    prepareMasks

    Prepares all mask internal objects according to what is defined in context This should be called prior to calling startRender() method.

    properties

    Should be reimplemented by subclasses to return a string map that contains the configuration information for the symbol layer.

    propertyDefinitions

    Returns the symbol layer property definitions.

    removeMasks

    When rendering, remove previously installed masks from context painter if recursive is True masks are removed recursively for all children symbol layers

    renderingPass

    Specifies the rendering pass in which this symbol layer should be rendered.

    restoreOldDataDefinedProperties

    Restores older data defined properties from string map.

    setColor

    Sets the "representative" color for the symbol layer.

    setDataDefinedProperties

    Sets the symbol layer's property collection, used for data defined overrides.

    setDataDefinedProperty

    Sets a data defined property for the layer.

    setEnabled

    Sets whether symbol layer is enabled and should be drawn.

    setFillColor

    Sets the fill color for the symbol layer.

    setId

    Set symbol layer identifier This id has to be unique in the whole project

    setLocked

    Sets whether the layer's colors are locked.

    setMapUnitScale

    param scale:

    setOutputUnit

    Sets the units to use for sizes and widths within the symbol layer.

    setPaintEffect

    Sets the current paint effect for the layer.

    setRenderingPass

    Specifies the rendering pass in which this symbol layer should be rendered.

    setStrokeColor

    Sets the stroke color for the symbol layer.

    setSubSymbol

    Sets layer's subsymbol.

    setUserFlags

    Sets user-controlled flags which control the symbol layer's behavior.

    shouldRenderUsingSelectionColor

    Returns True if the symbol layer should be rendered using the selection color from the render context.

    startFeatureRender

    Called before the layer will be rendered for a particular feature.

    startRender

    Called before a set of rendering operations commences on the supplied render context.

    stopFeatureRender

    Called after the layer has been rendered for a particular feature.

    stopRender

    Called after a set of rendering operations has finished on the supplied render context.

    strokeColor

    Returns the stroke color for the symbol layer.

    subSymbol

    Returns the symbol's sub symbol, if present.

    toSld

    Saves the symbol layer as SLD

    type

    rtype:

    Qgis.SymbolType

    usedAttributes

    Returns the set of attributes referenced by the layer.

    userFlags

    Returns user-controlled flags which control the symbol layer's behavior.

    usesMapUnits

    Returns True if the symbol layer has any components which use map unit based sizes.

    writeDxf

    write as DXF

class Property(value)

Bases: enum.IntEnum

Data definable properties.

  • PropertySize: Symbol size

  • PropertyAngle: Symbol angle

  • PropertyName: Name, eg shape name for simple markers

  • PropertyFillColor: Fill color

  • PropertyStrokeColor: Stroke color

  • PropertyStrokeWidth: Stroke width

  • PropertyStrokeStyle: Stroke style (eg solid, dashed)

  • PropertyOffset: Symbol offset

  • PropertyCharacter: Character, eg for font marker symbol layers

  • PropertyWidth: Symbol width

  • PropertyHeight: Symbol height

  • PropertyPreserveAspectRatio: Preserve aspect ratio between width and height

  • PropertyFillStyle: Fill style (eg solid, dots)

  • PropertyJoinStyle: Line join style

  • PropertySecondaryColor: Secondary color (eg for gradient fills)

  • PropertyLineAngle: Line angle, or angle of hash lines for hash line symbols

  • PropertyLineDistance: Distance between lines, or length of lines for hash line symbols

  • PropertyGradientType: Gradient fill type

  • PropertyCoordinateMode: Gradient coordinate mode

  • PropertyGradientSpread: Gradient spread mode

  • PropertyGradientReference1X: Gradient reference point 1 x

  • PropertyGradientReference1Y: Gradient reference point 1 y

  • PropertyGradientReference2X: Gradient reference point 2 x

  • PropertyGradientReference2Y: Gradient reference point 2 y

  • PropertyGradientReference1IsCentroid: Gradient reference point 1 is centroid

  • PropertyGradientReference2IsCentroid: Gradient reference point 2 is centroid

  • PropertyBlurRadius: Shapeburst blur radius

  • PropertyShapeburstUseWholeShape: Shapeburst use whole shape

  • PropertyShapeburstMaxDistance: Shapeburst fill from edge distance

  • PropertyShapeburstIgnoreRings: Shapeburst ignore rings

  • PropertyFile: Filename, eg for svg files

  • PropertyDistanceX: Horizontal distance between points

  • PropertyDistanceY: Vertical distance between points

  • PropertyDisplacementX: Horizontal displacement

  • PropertyDisplacementY: Vertical displacement

  • PropertyOpacity: Opacity

  • PropertyCustomDash: Custom dash pattern

  • PropertyCapStyle: Line cap style

  • PropertyPlacement: Line marker placement

  • PropertyInterval: Line marker interval

  • PropertyOffsetAlongLine: Offset along line

  • PropertyAverageAngleLength: Length to average symbol angles over

  • PropertyHorizontalAnchor: Horizontal anchor point

  • PropertyVerticalAnchor: Vertical anchor point

  • PropertyLayerEnabled: Whether symbol layer is enabled

  • PropertyArrowWidth: Arrow tail width

  • PropertyArrowStartWidth: Arrow tail start width

  • PropertyArrowHeadLength: Arrow head length

  • PropertyArrowHeadThickness: Arrow head thickness

  • PropertyArrowHeadType: Arrow head type

  • PropertyArrowType: Arrow type

  • PropertyOffsetX: Horizontal offset

  • PropertyOffsetY: Vertical offset

  • PropertyPointCount: Point count

  • PropertyRandomSeed: Random number seed

  • PropertyClipPoints: Whether markers should be clipped to polygon boundaries

  • PropertyDensityArea: Density area

  • PropertyFontFamily: Font family

  • PropertyFontStyle: Font style

  • PropertyDashPatternOffset: Dash pattern offset,

  • PropertyTrimStart: Trim distance from start of line (since QGIS 3.20)

  • PropertyTrimEnd: Trim distance from end of line (since QGIS 3.20)

  • PropertyLineStartWidthValue: Start line width for interpolated line renderer (since QGIS 3.22)

  • PropertyLineEndWidthValue: End line width for interpolated line renderer (since QGIS 3.22)

  • PropertyLineStartColorValue: Start line color for interpolated line renderer (since QGIS 3.22)

  • PropertyLineEndColorValue: End line color for interpolated line renderer (since QGIS 3.22)

  • PropertyMarkerClipping: Marker clipping mode (since QGIS 3.24)

  • PropertyRandomOffsetX: Random offset X (since QGIS 3.24)

  • PropertyRandomOffsetY: Random offset Y (since QGIS 3.24)

  • PropertyLineClipping: Line clipping mode (since QGIS 3.24)

canCauseArtifactsBetweenAdjacentTiles(self) bool

Returns True if the symbol layer rendering can cause visible artifacts across a single feature when the feature is rendered as a series of adjacent map tiles each containing a portion of the feature’s geometry.

The default implementation returns False.

New in version 3.18.

Return type:

bool

clone(self) QgsSymbolLayer

Shall be reimplemented by subclasses to create a deep copy of the instance.

Return type:

QgsSymbolLayer

color(self) QColor

Returns the “representative” color of the symbol layer.

Depending on the symbol layer type, this will have different meaning. For instance, a line symbol layer will generally return the stroke color of the layer, while a fill symbol layer will return the “fill” color instead of stroke.

Some symbol layer types will return an invalid QColor if they have no representative color associated (e.g. raster image based symbol layers).

See also

setColor()

See also

strokeColor()

See also

fillColor()

Return type:

QColor

copyDataDefinedProperties(self, destLayer: QgsSymbolLayer)

Copies all data defined properties of this layer to another symbol layer.

Parameters:

destLayer (QgsSymbolLayer) – destination layer

copyPaintEffect(self, destLayer: QgsSymbolLayer)

Copies paint effect of this layer to another symbol layer

Parameters:

destLayer (QgsSymbolLayer) – destination layer

dataDefinedProperties(self) QgsPropertyCollection

Returns a reference to the symbol layer’s property collection, used for data defined overrides.

See also

Property

Return type:

QgsPropertyCollection

drawPreviewIcon(self, context: QgsSymbolRenderContext, size: QSize)
Parameters:
dxfAngle(self, context: QgsSymbolRenderContext) float

Gets angle

Parameters:

context (QgsSymbolRenderContext) –

Return type:

float

dxfBrushColor(self, context: QgsSymbolRenderContext) QColor

Gets brush/fill color

Parameters:

context (QgsSymbolRenderContext) –

Return type:

QColor

dxfBrushStyle(self) Qt.BrushStyle

Gets brush/fill style

Return type:

Qt.BrushStyle

dxfColor(self, context: QgsSymbolRenderContext) QColor

Gets color

Parameters:

context (QgsSymbolRenderContext) –

Return type:

QColor

dxfCustomDashPattern(self) Tuple[List[float], Qgis.RenderUnit]

Gets dash pattern

Return type:

Tuple[List[float], Qgis.RenderUnit]

dxfOffset(self, e: QgsDxfExport, context: QgsSymbolRenderContext) float

Gets offset

Parameters:
Return type:

float

dxfPenStyle(self) Qt.PenStyle

Gets pen style

Return type:

Qt.PenStyle

dxfSize(self, e: QgsDxfExport, context: QgsSymbolRenderContext) float

Gets marker size

Parameters:
Return type:

float

dxfWidth(self, e: QgsDxfExport, context: QgsSymbolRenderContext) float

Gets line width

Parameters:
Return type:

float

enabled(self) bool

Returns True if symbol layer is enabled and will be drawn.

See also

setEnabled()

Return type:

bool

estimateMaxBleed(self, context: QgsRenderContext) float

Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when drawn in the specified /a context. For example, polygons drawn with an stroke will draw half the width of the stroke outside of the polygon. This amount is estimated, since it may be affected by data defined symbology rules.

Parameters:

context (QgsRenderContext) –

Return type:

float

fillColor(self) QColor

Returns the fill color for the symbol layer.

This property is not supported by all symbol layer types, only those with a fill component. Symbol layers without a fill component will return an invalid QColor.

See also

setFillColor()

See also

color()

See also

strokeColor()

Return type:

QColor

flags(self) Qgis.SymbolLayerFlags

Returns flags which control the symbol layer’s behavior.

New in version 3.22.

Return type:

Qgis.SymbolLayerFlags

hasDataDefinedProperties(self) bool

Returns True if the symbol layer (or any of its sub-symbols) contains data defined properties.

New in version 3.4.5.

Return type:

bool

id(self) str

Returns symbol layer identifier This id is unique in the whole project

New in version 3.30.

Return type:

str

installMasks(self, context: QgsRenderContext, recursive: bool)

When rendering, install masks on context painter if recursive is True masks are installed recursively for all children symbol layers

See also

prepareMasks()

See also

removeMasks()

New in version 3.30.

Parameters:
isCompatibleWithSymbol(self, symbol: QgsSymbol) bool

Returns if the layer can be used below the specified symbol

Parameters:

symbol (QgsSymbol) –

Return type:

bool

isLocked(self) bool

Returns True if the symbol layer colors are locked and the layer will ignore any symbol-level color changes.

See also

setLocked()

Return type:

bool

layerType(self) str

Returns a string that represents this layer type. Used for serialization. Should match with the string used to register this symbol layer in the registry.

Return type:

str

mapUnitScale(self) QgsMapUnitScale
Return type:

QgsMapUnitScale

masks(self) List[QgsSymbolLayerReference]

Returns masks defined by this symbol layer. This is a list of symbol layers of other layers that should be occluded.

New in version 3.12.

Return type:

List[QgsSymbolLayerReference]

ogrFeatureStyle(self, mmScaleFactor: float, mapUnitScaleFactor: float) str
Parameters:
  • mmScaleFactor (float) –

  • mapUnitScaleFactor (float) –

Return type:

str

outputUnit(self) Qgis.RenderUnit

Returns the units to use for sizes and widths within the symbol layer. Individual symbol layer subclasses will interpret this in different ways, e.g., a marker symbol layer may use it to specify the units for the marker size, while a line symbol layer may use it to specify the units for the line width.

Return type:

Qgis.RenderUnit

Returns:

output unit, or QgsUnitTypes.RenderUnknownUnit if the symbol layer contains mixed units

See also

setOutputUnit()

paintEffect(self) QgsPaintEffect

Returns the current paint effect for the layer.

Return type:

QgsPaintEffect

Returns:

paint effect

See also

setPaintEffect()

prepareExpressions(self, context: QgsSymbolRenderContext)

Prepares all data defined property expressions for evaluation. This should be called prior to evaluating data defined properties.

Parameters:

context (QgsSymbolRenderContext) – symbol render context

prepareMasks(self, context: QgsSymbolRenderContext)

Prepares all mask internal objects according to what is defined in context This should be called prior to calling startRender() method.

New in version 3.26.

Parameters:

context (QgsSymbolRenderContext) –

properties(self) Dict[str, Any]

Should be reimplemented by subclasses to return a string map that contains the configuration information for the symbol layer. This is used to serialize a symbol layer perstistently.

Return type:

Dict[str, Any]

propertyDefinitions() Dict[int, QgsPropertyDefinition]

Returns the symbol layer property definitions.

Return type:

Dict[int, QgsPropertyDefinition]

removeMasks(self, context: QgsRenderContext, recursive: bool)

When rendering, remove previously installed masks from context painter if recursive is True masks are removed recursively for all children symbol layers

See also

prepareMasks()

See also

installMasks()

New in version 3.30.

Parameters:
renderingPass(self) int

Specifies the rendering pass in which this symbol layer should be rendered. The lower the number, the lower the symbol will be rendered. 0: first pass, 1: second pass, … Defaults to 0

Return type:

int

restoreOldDataDefinedProperties(self, stringMap: Dict[str, Any])

Restores older data defined properties from string map.

Parameters:

stringMap (Dict[str) –

setColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the “representative” color for the symbol layer.

Depending on the symbol layer type, this will have different meaning. For instance, a line symbol layer will generally set the stroke color of the layer, while a fill symbol layer will set the “fill” color instead of stroke.

See also

color()

See also

setStrokeColor()

See also

setFillColor()

Parameters:

color (Union[QColor) –

setDataDefinedProperties(self, collection: QgsPropertyCollection)

Sets the symbol layer’s property collection, used for data defined overrides.

Parameters:

collection (QgsPropertyCollection) – property collection. Existing properties will be replaced.

setDataDefinedProperty(self, key: QgsSymbolLayer.Property, property: QgsProperty)

Sets a data defined property for the layer. Any existing property with the same key will be overwritten.

See also

Property

Parameters:
setEnabled(self, enabled: bool)

Sets whether symbol layer is enabled and should be drawn. Disabled layers are not drawn, but remain part of the symbol and can be re-enabled when desired.

See also

enabled()

Parameters:

enabled (bool) –

setFillColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the fill color for the symbol layer.

This property is not supported by all symbol layer types, only those with a fill component.

See also

fillColor()

See also

setColor()

See also

setStrokeColor()

Parameters:

color (Union[QColor) –

setId(self, id: str)

Set symbol layer identifier This id has to be unique in the whole project

New in version 3.30.

Parameters:

id (str) –

setLocked(self, locked: bool)

Sets whether the layer’s colors are locked.

If locked is True then the symbol layer colors are locked and the layer will ignore any symbol-level color changes.

See also

isLocked()

Parameters:

locked (bool) –

setMapUnitScale(self, scale: QgsMapUnitScale)
Parameters:

scale (QgsMapUnitScale) –

setOutputUnit(self, unit: Qgis.RenderUnit)

Sets the units to use for sizes and widths within the symbol layer. Individual symbol layer subclasses will interpret this in different ways, e.g., a marker symbol layer may use it to specify the units for the marker size, while a line symbol layer may use it to specify the units for the line width.

Parameters:

unit (Qgis.RenderUnit) – output units

See also

outputUnit()

setPaintEffect(self, effect: QgsPaintEffect)

Sets the current paint effect for the layer.

Parameters:

effect (QgsPaintEffect) – paint effect. Ownership is transferred to the layer.

See also

paintEffect()

setRenderingPass(self, renderingPass: int)

Specifies the rendering pass in which this symbol layer should be rendered. The lower the number, the lower the symbol will be rendered. 0: first pass, 1: second pass, … Defaults to 0

Parameters:

renderingPass (int) –

setStrokeColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the stroke color for the symbol layer.

This property is not supported by all symbol layer types, only those with a stroke component.

See also

strokeColor()

See also

setColor()

See also

setFillColor()

Parameters:

color (Union[QColor) –

setSubSymbol(self, symbol: QgsSymbol) bool

Sets layer’s subsymbol. takes ownership of the passed symbol

Parameters:

symbol (QgsSymbol) –

Return type:

bool

setUserFlags(self, flags: Qgis.SymbolLayerUserFlags | Qgis.SymbolLayerUserFlag)

Sets user-controlled flags which control the symbol layer’s behavior.

See also

userFlags()

New in version 3.34.

Parameters:

flags (Union[Qgis.SymbolLayerUserFlags) –

shouldRenderUsingSelectionColor(self, context: QgsSymbolRenderContext) bool

Returns True if the symbol layer should be rendered using the selection color from the render context.

New in version 3.34.

Parameters:

context (QgsSymbolRenderContext) –

Return type:

bool

startFeatureRender(self, feature: QgsFeature, context: QgsRenderContext)

Called before the layer will be rendered for a particular feature.

This is always followed by a call to stopFeatureRender() after the feature has been completely rendered (i.e. all parts have been rendered).

The default implementation does nothing.

Note

In some circumstances, startFeatureRender() and stopFeatureRender() may not be called before a symbol layer is rendered. E.g., when a symbol layer is being rendered in isolation and not as a result of rendering a feature (for instance, when rendering a legend patch or other non-feature based shape).

See also

startRender()

New in version 3.12.

Parameters:
startRender(self, context: QgsSymbolRenderContext)

Called before a set of rendering operations commences on the supplied render context.

This is always followed by a call to stopRender() after all rendering operations have been completed.

Subclasses can use this method to prepare for a set of rendering operations, e.g. by pre-evaluating paths or images to render, and performing other one-time optimisations.

See also

stopRender()

Parameters:

context (QgsSymbolRenderContext) –

stopFeatureRender(self, feature: QgsFeature, context: QgsRenderContext)

Called after the layer has been rendered for a particular feature.

This is always preceded by a call to startFeatureRender() just before the feature will be rendered.

The default implementation does nothing.

Note

In some circumstances, startFeatureRender() and stopFeatureRender() may not be called before a symbol layer is rendered. E.g., when a symbol layer is being rendered in isolation and not as a result of rendering a feature (for instance, when rendering a legend patch or other non-feature based shape).

See also

stopRender()

New in version 3.12.

Parameters:
stopRender(self, context: QgsSymbolRenderContext)

Called after a set of rendering operations has finished on the supplied render context.

This is always preceded by a call to startRender() before all rendering operations are commenced.

Subclasses can use this method to cleanup after a set of rendering operations.

See also

startRender()

Parameters:

context (QgsSymbolRenderContext) –

strokeColor(self) QColor

Returns the stroke color for the symbol layer.

This property is not supported by all symbol layer types, only those with a stroke component. Symbol layers without a stroke component will return an invalid QColor.

See also

setStrokeColor()

See also

color()

See also

fillColor()

Return type:

QColor

subSymbol(self) QgsSymbol

Returns the symbol’s sub symbol, if present.

Return type:

QgsSymbol

toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, Any])

Saves the symbol layer as SLD

Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • props (Dict[str) –

type(self) Qgis.SymbolType
Return type:

Qgis.SymbolType

usedAttributes(self, context: QgsRenderContext) Set[str]

Returns the set of attributes referenced by the layer. This includes attributes required by any data defined properties associated with the layer.

Parameters:

context (QgsRenderContext) –

Return type:

Set[str]

userFlags(self) Qgis.SymbolLayerUserFlags

Returns user-controlled flags which control the symbol layer’s behavior.

See also

setUserFlags()

New in version 3.34.

Return type:

Qgis.SymbolLayerUserFlags

usesMapUnits(self) bool

Returns True if the symbol layer has any components which use map unit based sizes.

New in version 3.18.

Return type:

bool

writeDxf(self, e: QgsDxfExport, mmMapUnitScaleFactor: float, layerName: str, context: QgsSymbolRenderContext, shift: QPointF | QPoint = QPointF(0, 0)) bool

write as DXF

Parameters:
Return type:

bool