Class: QgsSymbolRenderContext

Encapsulates the context in which a symbol is being rendered.

Methods

expressionContextScope

This scope is always available when a symbol of this type is being rendered.

feature

Returns the current feature being rendered.

fields

Fields of the layer.

forceVectorRendering

Returns True if symbol must be rendered using vector methods, and optimisations like pre-rendered images must be disabled.

geometryPartCount

Part count of current geometry

geometryPartNum

Part number of current geometry

mapUnitScale

opacity

Returns the opacity for the symbol.

originalGeometryType

Returns the geometry type for the original feature geometry being rendered.

outputLineWidth

outputPixelSize

outputUnit

Returns the output unit for the context.

patchShape

Returns the symbol patch shape, to use if rendering symbol preview icons.

renderContext

Returns a reference to the context's render context.

renderHints

Returns the rendering hint flags for the symbol.

selected

Returns True if symbols should be rendered using the selected symbol coloring and style.

setExpressionContextScope

Set an expression scope for this symbol.

setFeature

setGeometryPartCount

Sets the part count of current geometry

setGeometryPartNum

Sets the part number of current geometry

setMapUnitScale

setOpacity

Sets the opacity for the symbol.

setOriginalGeometryType

Sets the geometry type for the original feature geometry being rendered.

setOriginalValueVariable

Sets the original value variable value for data defined symbology

setOutputUnit

Sets the output unit for the context.

setPatchShape

Sets the symbol patch shape, to use if rendering symbol preview icons.

setRenderHint

Sets a rendering hint flag for the symbol.

setRenderHints

Sets rendering hint flags for the symbol.

setSelected

Sets whether symbols should be rendered using the selected symbol coloring and style.

class qgis.core.QgsSymbolRenderContext[source]

Bases: object

__init__(c: QgsRenderContext, u: Qgis.RenderUnit, opacity: float = 1, selected: bool = False, renderHints: Qgis.SymbolRenderHints | Qgis.SymbolRenderHint = Qgis.SymbolRenderHints(), f: QgsFeature | None = None, fields: QgsFields = QgsFields(), mapUnitScale: QgsMapUnitScale = QgsMapUnitScale())

Constructor for QgsSymbolRenderContext

Parameters:
expressionContextScope(self) QgsExpressionContextScope | None[source]

This scope is always available when a symbol of this type is being rendered.

Return type:

Optional[QgsExpressionContextScope]

Returns:

An expression scope for details about this symbol

feature(self) QgsFeature | None[source]

Returns the current feature being rendered. This may be None.

Return type:

Optional[QgsFeature]

fields(self) QgsFields[source]

Fields of the layer. Currently only available in startRender() calls to allow symbols with data-defined properties prepare the expressions (other times fields() returns an empty QgsFields object).

Return type:

QgsFields

forceVectorRendering(self) bool[source]

Returns True if symbol must be rendered using vector methods, and optimisations like pre-rendered images must be disabled.

Added in version 3.40.

Return type:

bool

geometryPartCount(self) int[source]

Part count of current geometry

Return type:

int

geometryPartNum(self) int[source]

Part number of current geometry

Return type:

int

mapUnitScale(self) QgsMapUnitScale[source]

Deprecated since version 3.40.

Will be removed in QGIS 4.0.

Return type:

QgsMapUnitScale

opacity(self) float[source]

Returns the opacity for the symbol.

Return type:

float

Returns:

opacity value between 0 (fully transparent) and 1 (fully opaque)

See also

setOpacity()

originalGeometryType(self) Qgis.GeometryType[source]

Returns the geometry type for the original feature geometry being rendered. This can be useful if symbol layers alter their appearance based on geometry type - eg offsetting a simple line style will look different if the simple line is rendering a polygon feature (a closed buffer) vs a line feature (an unclosed offset line).

Return type:

Qgis.GeometryType

outputLineWidth(self, width: float) float[source]

Deprecated since version 3.40.

Use the size conversion methods in QgsRenderContext instead.

Parameters:

width (float)

Return type:

float

outputPixelSize(self, size: float) float[source]

Deprecated since version 3.40.

Use the size conversion methods in QgsRenderContext instead.

Parameters:

size (float)

Return type:

float

outputUnit(self) Qgis.RenderUnit[source]

Returns the output unit for the context.

Deprecated since version 3.40: No longer used and will be removed in QGIS 4.0.

Return type:

Qgis.RenderUnit

patchShape(self) QgsLegendPatchShape | None[source]

Returns the symbol patch shape, to use if rendering symbol preview icons.

See also

setPatchShape()

Added in version 3.14.

Return type:

Optional[QgsLegendPatchShape]

renderContext(self) QgsRenderContext

Returns a reference to the context’s render context.

Return type:

QgsRenderContext

renderHints(self) Qgis.SymbolRenderHints[source]

Returns the rendering hint flags for the symbol.

See also

setRenderHints()

Return type:

Qgis.SymbolRenderHints

selected(self) bool[source]

Returns True if symbols should be rendered using the selected symbol coloring and style.

See also

setSelected()

Return type:

bool

setExpressionContextScope(self, contextScope: QgsExpressionContextScope | None)[source]

Set an expression scope for this symbol.

Will take ownership.

Parameters:

contextScope (Optional[QgsExpressionContextScope]) – An expression scope for details about this symbol

setFeature(self, f: QgsFeature | None)[source]
Parameters:

f (Optional[QgsFeature])

setGeometryPartCount(self, count: int)[source]

Sets the part count of current geometry

Parameters:

count (int)

setGeometryPartNum(self, num: int)[source]

Sets the part number of current geometry

Parameters:

num (int)

setMapUnitScale(self, scale: QgsMapUnitScale)[source]

Deprecated since version 3.40.

Will be removed in QGIS 4.0.

Parameters:

scale (QgsMapUnitScale)

setOpacity(self, opacity: float)[source]

Sets the opacity for the symbol.

Parameters:

opacity (float) – opacity value between 0 (fully transparent) and 1 (fully opaque)

See also

opacity()

setOriginalGeometryType(self, type: Qgis.GeometryType)[source]

Sets the geometry type for the original feature geometry being rendered.

Parameters:

type (Qgis.GeometryType)

setOriginalValueVariable(self, value: Any)[source]

Sets the original value variable value for data defined symbology

Parameters:

value (Any) – value for original value variable. This usually represents the symbol property value before any data defined overrides have been applied.

setOutputUnit(self, u: Qgis.RenderUnit)[source]

Sets the output unit for the context.

Deprecated since version 3.40: No longer used and will be removed in QGIS 4.0.

Parameters:

u (Qgis.RenderUnit)

setPatchShape(self, shape: QgsLegendPatchShape)[source]

Sets the symbol patch shape, to use if rendering symbol preview icons.

See also

patchShape()

Added in version 3.14.

Parameters:

shape (QgsLegendPatchShape)

setRenderHint(self, hint: Qgis.SymbolRenderHint, enabled: bool = True)[source]

Sets a rendering hint flag for the symbol.

See also

renderHints()

Added in version 3.40.

Parameters:
setRenderHints(self, hints: Qgis.SymbolRenderHints | Qgis.SymbolRenderHint)[source]

Sets rendering hint flags for the symbol.

See also

renderHints()

Parameters:

hints (Union[Qgis.SymbolRenderHints, Qgis.SymbolRenderHint])

setSelected(self, selected: bool)[source]

Sets whether symbols should be rendered using the selected symbol coloring and style.

See also

selected()

Parameters:

selected (bool)