Class: QgsRenderContext

class qgis.core.QgsRenderContext

Bases: QgsTemporalRangeObject

Contains information about the context of a rendering operation.

The context of a rendering operation defines properties such as the conversion ratio between screen and map units, the extents to be rendered etc.

Enums

Flag

alias of RenderContextFlag

TextRenderFormat

Bases: enum.IntEnum

Methods

addSymbolLayerClipGeometry

Add a clip geometry to be applied to the symbolLayer before rendering.

addSymbolLayerClipPath

Add a clip path to be applied to the symbolLayer before rendering

clearCustomRenderingFlag

Clears the specified custom rendering flag.

clippingRegions

Returns the list of clipping regions to apply during the render.

convertFromMapUnits

Converts a size from map units to the specified units.

convertMetersToMapUnits

Convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits note When the sourceCrs() is geographic, the center of the Extent will be used

convertToMapUnits

Converts a size from the specified units to map units.

convertToPainterUnits

Converts a size from the specified units to painter units (pixels).

coordinateTransform

Returns the current coordinate transform for the context.

currentFrame

Returns the current frame number of the map (in frames per second), for maps which are part of an animation.

currentMaskId

Returns the current mask id, which can be used with maskPainter()

customRenderingFlags

Gets custom rendering flags.

deviceOutputSize

Returns the device output size of the render.

devicePixelRatio

Returns the device pixel ratio.

disabledSymbolLayers

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

disabledSymbolLayersV2

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

distanceArea

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

dpiTarget

Returns the targeted DPI for rendering.

drawEditingInformation

Returns True if edit markers should be drawn during the render operation.

elevationMap

Returns the destination elevation map for the render operation.

expressionContext

Gets the expression context.

extent

When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the layer's CRS).

featureClipGeometry

Returns the geometry to use to clip features at render time.

featureFilterProvider

Gets the filter feature provider used for additional filtering of rendered features.

feedback

Returns the feedback object that can be queried regularly during rendering to check if rendering should be canceled, if set.

flags

Returns combination of flags used for rendering.

forceVectorOutput

Returns True if rendering operations should use vector operations instead of any faster raster shortcuts.

frameRate

Returns the frame rate of the map, for maps which are part of an animation.

fromMapSettings

create initialized QgsRenderContext instance from given QgsMapSettings

fromQPainter

Creates a default render context given a pixel based QPainter destination.

geometry

Returns pointer to the unsegmentized geometry

hasRenderedFeatureHandlers

Returns True if the context has any rendered feature handlers.

imageFormat

Returns the QImage format which should be used for QImages created during rendering.

isGuiPreview

Returns the Gui preview mode.

isSymbolLayerEnabled

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

mapExtent

Returns the original extent of the map being rendered.

mapToPixel

Returns the context's map to pixel transform, which transforms between map coordinates and device coordinates.

maskIdProvider

Returns the mask id provider attached to the context.

maskPainter

Returns a mask QPainter for the render operation.

outputSize

Returns the size of the resulting rendered image, in pixels.

painter

Returns the destination QPainter for the render operation.

pathResolver

Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.

previewRenderPainter

Returns the const destination QPainter for temporary in-progress preview renders.

renderedFeatureHandlers

Returns the list of rendered feature handlers to use while rendering map layers.

rendererScale

Returns the renderer map scale.

rendererUsage

Returns the renderer usage

renderingStopped

Returns True if the rendering operation has been stopped and any ongoing rendering should be canceled immediately.

scaleFactor

Returns the scaling factor for the render to convert painter units to physical sizes.

segmentationTolerance

Gets the segmentation tolerance applied when rendering curved geometries

segmentationToleranceType

Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

selectionColor

Returns the color to use when rendering selected features.

setCoordinateTransform

Sets the current coordinate transform for the context.

setCurrentFrame

Sets the current frame of the map, for maps which are part of an animation.

setCurrentMaskId

Stores a mask id as the "current" one.

setCustomRenderingFlag

Sets a custom rendering flag.

setDevicePixelRatio

Sets the device pixel ratio.

setDisabledSymbolLayers

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

setDisabledSymbolLayersV2

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

setDistanceArea

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

setDpiTarget

Sets the targeted dpi for rendering.

setDrawEditingInformation

Sets whether edit markers should be drawn during the render operation.

setElevationMap

Sets the destination elevation map for the render operation.

setExpressionContext

Sets the expression context.

setExtent

When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the layer's CRS).

setFeatureClipGeometry

Sets a geometry to use to clip features at render time.

setFeatureFilterProvider

Set a filter feature provider used for additional filtering of rendered features.

setFeedback

Attach a feedback object that can be queried regularly during rendering to check if rendering should be canceled.

setFlag

Enable or disable a particular flag (other flags are not affected)

setFlags

Set combination of flags that will be used for rendering.

setForceVectorOutput

Sets whether rendering operations should use vector operations instead of any faster raster shortcuts.

setFrameRate

Sets the frame rate of the map (in frames per second), for maps which are part of an animation.

setGeometry

Sets pointer to original (unsegmentized) geometry

setImageFormat

Sets QImage format which should be used for QImages created during rendering.

setIsGuiPreview

Sets GUI preview mode.

setMapExtent

Sets the original extent of the map being rendered.

setMapToPixel

Sets the context's map to pixel transform, which transforms between map coordinates and device coordinates.

setMaskIdProvider

Attaches a mask id provider to the context.

setMaskPainter

Sets a mask QPainter for the render operation.

setOutputSize

Sets the size of the resulting rendered image, in pixels.

setPainter

Sets the destination QPainter for the render operation.

setPainterFlagsUsingContext

Sets relevant flags on a destination painter, using the flags and settings currently defined for the render context.

setPathResolver

Sets the path resolver for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.

setPreviewRenderPainter

Sets the destination painter for temporary in-progress preview renders.

setRendererScale

Sets the renderer map scale.

setRendererUsage

Sets the renderer usage

setRenderingStopped

Sets whether the rendering operation has been stopped and any ongoing rendering should be canceled immediately.

setScaleFactor

Sets the scaling factor for the render to convert painter units to physical sizes.

setSegmentationTolerance

Sets the segmentation tolerance applied when rendering curved geometries

setSegmentationToleranceType

Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

setSelectionColor

Sets the color to use when rendering selected features.

setShowSelection

Sets whether vector selections should be shown in the rendered map

setSymbologyReferenceScale

Sets the symbology reference scale.

setTextRenderFormat

Sets the text render format, which dictates how text is rendered (e.g. as paths or real text objects).

setTextureOrigin

Sets the texture origin, which should be used as a brush transform when rendering using QBrush objects.

setTransformContext

Sets the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

setUseAdvancedEffects

Used to enable or disable advanced effects such as blend modes

setUseRenderingOptimization

Sets whether the rendering optimization (geometry simplification) should be executed

setVectorSimplifyMethod

Sets the simplification setting to use when rendering vector layers.

setZRange

Sets the range of z-values which should be rendered.

showSelection

Returns True if vector selections should be shown in the rendered map

symbolLayerClipGeometries

Returns clipping geometries to be applied to the symbolLayer before rendering

symbolLayerClipPaths

Returns clip paths to be applied to the symbolLayer before rendering

symbologyReferenceScale

Returns the symbology reference scale.

testFlag

Check whether a particular flag is enabled.

textRenderFormat

Returns the text render format, which dictates how text is rendered (e.g. as paths or real text objects).

textureOrigin

Returns the texture origin, which should be used as a brush transform when rendering using QBrush objects.

transformContext

Returns the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

useAdvancedEffects

Returns True if advanced effects such as blend modes such be used

useRenderingOptimization

Returns True if the rendering optimization (geometry simplification) can be executed

vectorSimplifyMethod

Returns the simplification settings to use when rendering vector layers.

zRange

Returns the range of z-values which should be rendered.

Flag

alias of RenderContextFlag

Flags

alias of RenderContextFlags

class TextRenderFormat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Options for rendering text.

Added in version 3.22.

  • TextFormatAlwaysOutlines: Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality rendering, even when using a raster paint surface (where sub-pixel path based text rendering is superior to sub-pixel text-based rendering). The downside is that text is converted to paths only, so users cannot open created vector outputs for post-processing in other applications and retain text editability. This setting also guarantees complete compatibility with the full range of formatting options available through QgsTextRenderer and QgsTextFormat, some of which may not be possible to reproduce when using a vector-based paint surface and TextFormatAlwaysText mode. A final benefit to this setting is that vector exports created using text as outlines do not require all users to have the original fonts installed in order to display the text in its original style.

  • TextFormatAlwaysText: Always render text as text objects. While this mode preserves text objects as text for post-processing in external vector editing applications, it can result in rendering artifacts or poor quality rendering, depending on the text format settings. Even with raster based paint devices, TextFormatAlwaysText can result in inferior rendering quality to TextFormatAlwaysOutlines. When rendering using TextFormatAlwaysText to a vector based device (e.g. PDF or SVG), care must be taken to ensure that the required fonts are available to users when opening the created files, or default fallback fonts will be used to display the output instead. (Although PDF exports MAY automatically embed some fonts when possible, depending on the user’s platform).

baseClass

alias of Qgis

addSymbolLayerClipGeometry(self, symbolLayerId: str | None, geometry: QgsGeometry)

Add a clip geometry to be applied to the symbolLayer before rendering.

Added in version 3.38.

Parameters:
addSymbolLayerClipPath(self, symbolLayerId: str | None, path: QPainterPath)

Add a clip path to be applied to the symbolLayer before rendering

Added in version 3.26.

Parameters:
  • symbolLayerId (Optional[str])

  • path (QPainterPath)

clearCustomRenderingFlag(self, flag: str | None)

Clears the specified custom rendering flag.

Parameters:

flag (Optional[str]) – the flag name

Added in version 3.12.

clippingRegions(self) List[QgsMapClippingRegion]

Returns the list of clipping regions to apply during the render.

These regions are always in the final destination CRS for the map.

Added in version 3.16.

Return type:

List[QgsMapClippingRegion]

convertFromMapUnits(self, sizeInMapUnits: float, outputUnit: Qgis.RenderUnit) float

Converts a size from map units to the specified units.

Parameters:
Return type:

float

convertMetersToMapUnits(self, meters: float) float

Convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits note When the sourceCrs() is geographic, the center of the Extent will be used

Parameters:

meters (float)

Return type:

float

convertToMapUnits(self, size: float, unit: Qgis.RenderUnit, scale: QgsMapUnitScale = QgsMapUnitScale()) float

Converts a size from the specified units to map units. The conversion respects the limits specified by the optional scale parameter.

Parameters:
Return type:

float

convertToPainterUnits(self, size: float, unit: Qgis.RenderUnit, scale: QgsMapUnitScale = QgsMapUnitScale(), property: Qgis.RenderSubcomponentProperty = Qgis.RenderSubcomponentProperty.Generic) float

Converts a size from the specified units to painter units (pixels). The conversion respects the limits specified by the optional scale parameter.

Since QGIS 3.22 the optional property argument can be used to specify the associated property. This is used in some contexts to refine the converted size. For example, a Qgis.RenderSubcomponentProperty.BlurSize property will be limited to a suitably fast range when the render context has the Qgis.RenderContextFlag.RenderSymbolPreview set.

Parameters:
  • size (float)

  • unit (Qgis.RenderUnit)

  • scale (QgsMapUnitScale = QgsMapUnitScale())

  • property (Qgis.RenderSubcomponentProperty = Qgis.RenderSubcomponentProperty.Generic)

Return type:

float

coordinateTransform(self) QgsCoordinateTransform

Returns the current coordinate transform for the context.

This represents the coordinate transform required to transform a layer which is being rendered back to the CRS of the rendered map. If no coordinate transformation is required, or the render context is not associated with a map layer render, then an invalid coordinate transformation is returned.

Return type:

QgsCoordinateTransform

currentFrame(self) int

Returns the current frame number of the map (in frames per second), for maps which are part of an animation.

Returns -1 if the map is not associated with an animation.

Added in version 3.26.

Return type:

int

currentMaskId(self) int

Returns the current mask id, which can be used with maskPainter()

See also

maskPainter()

Added in version 3.12.

Return type:

int

customRenderingFlags(self) Dict[str, Any]

Gets custom rendering flags. Layers might honour these to alter their rendering.

Return type:

Dict[str, Any]

Returns:

a map of custom flags

Added in version 3.12.

deviceOutputSize(self) QSize

Returns the device output size of the render.

This is equivalent to the output size multiplicated by the device pixel ratio.

See also

outputSize()

See also

setOutputSize()

Added in version 3.22.

Return type:

QSize

devicePixelRatio(self) float

Returns the device pixel ratio.

Common values are 1 for normal-dpi displays and 2 for high-dpi “retina” displays.

Added in version 3.22.

Return type:

float

disabledSymbolLayers(self) Set[QgsSymbolLayer]

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

Returns the list of disabled symbol layers.

Added in version 3.12.

Deprecated since version QGIS: 3.30 and replaced with disabledSymbolLayersV2

Return type:

Set[QgsSymbolLayer]

disabledSymbolLayersV2(self) Set[str]

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

Returns the list of disabled symbol layer ids.

Added in version 3.30.

Return type:

Set[str]

distanceArea(self) QgsDistanceArea

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

Return type:

QgsDistanceArea

dpiTarget(self) float

Returns the targeted DPI for rendering.

See also

setDpiTarget()

Added in version 3.20.

Return type:

float

drawEditingInformation(self) bool

Returns True if edit markers should be drawn during the render operation.

Return type:

bool

elevationMap(self) QgsElevationMap | None

Returns the destination elevation map for the render operation.

Added in version 3.30.

Return type:

Optional[QgsElevationMap]

expressionContext(self) QgsExpressionContext

Gets the expression context. This context should be used for all expression evaluation associated with this render context.

Return type:

QgsExpressionContext

extent(self) QgsRectangle

When rendering a map layer, calling this method returns the “clipping” extent for the layer (in the layer’s CRS).

This extent is a “worst-case” scenario, which is guaranteed to cover the complete visible portion of the layer when it is rendered to a map. It is often larger than the actual visible portion of that layer.

Warning

For some layers, depending on the visible extent and the coordinate transforms involved, this extent will represent the entire globe. This method should never be used to determine the actual visible extent of a map render.

See also

setExtent()

See also

mapExtent()

Return type:

QgsRectangle

featureClipGeometry(self) QgsGeometry

Returns the geometry to use to clip features at render time.

When vector features are rendered, they should be clipped to this geometry.

Warning

The clipping must take effect for rendering the feature’s symbol only, and should never be applied directly to the feature being rendered. Doing so would impact the results of rendering rules which rely on feature geometry, such as a rule-based renderer using the feature’s area.

Added in version 3.16.

Return type:

QgsGeometry

featureFilterProvider(self) QgsFeatureFilterProvider | None

Gets the filter feature provider used for additional filtering of rendered features.

Return type:

Optional[QgsFeatureFilterProvider]

Returns:

the filter feature provider

feedback(self) QgsFeedback | None

Returns the feedback object that can be queried regularly during rendering to check if rendering should be canceled, if set. Maybe be None.

See also

setFeedback()

Added in version 3.22.

Return type:

Optional[QgsFeedback]

flags(self) Qgis.RenderContextFlags

Returns combination of flags used for rendering.

Return type:

Qgis.RenderContextFlags

forceVectorOutput(self) bool

Returns True if rendering operations should use vector operations instead of any faster raster shortcuts.

Return type:

bool

frameRate(self) float

Returns the frame rate of the map, for maps which are part of an animation.

Returns -1 if the map is not associated with an animation.

See also

setFrameRate()

Added in version 3.26.

Return type:

float

fromMapSettings(mapSettings: QgsMapSettings) QgsRenderContext

create initialized QgsRenderContext instance from given QgsMapSettings

Parameters:

mapSettings (QgsMapSettings)

Return type:

QgsRenderContext

fromQPainter(painter: QPainter | None) QgsRenderContext

Creates a default render context given a pixel based QPainter destination. If no painter is specified or the painter has no device, then a default DPI of 88 will be assumed.

Parameters:

painter (Optional[QPainter])

Return type:

QgsRenderContext

geometry(self) QgsAbstractGeometry | None

Returns pointer to the unsegmentized geometry

Return type:

Optional[QgsAbstractGeometry]

hasRenderedFeatureHandlers(self) bool

Returns True if the context has any rendered feature handlers.

Added in version 3.10.

Return type:

bool

imageFormat(self) QImage.Format

Returns the QImage format which should be used for QImages created during rendering.

See also

setImageFormat()

Added in version 3.22.

Return type:

QImage.Format

isGuiPreview(self) bool

Returns the Gui preview mode. GUI preview mode is used to change the behavior of some renderings when they are done to preview of symbology in the GUI. This is especially used to display mask symbol layers rather than painting them in a mask painter, which is not meant to be visible, by definition.

See also

isGuiPreview()

Added in version 3.12.

Return type:

bool

isSymbolLayerEnabled(self, layer: QgsSymbolLayer | None) bool

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

Checks whether a given symbol layer has been disabled for the current pass.

Added in version 3.12.

Parameters:

layer (Optional[QgsSymbolLayer])

Return type:

bool

mapExtent(self) QgsRectangle

Returns the original extent of the map being rendered.

Unlike extent(), this extent is always in the final destination CRS for the map render and represents the exact bounds of the map being rendered.

See also

extent()

See also

setMapExtent()

Added in version 3.4.8.

Return type:

QgsRectangle

mapToPixel(self) QgsMapToPixel

Returns the context’s map to pixel transform, which transforms between map coordinates and device coordinates.

See also

setMapToPixel()

Return type:

QgsMapToPixel

maskIdProvider(self) QgsMaskIdProvider | None

Returns the mask id provider attached to the context.

Added in version 3.12.

Return type:

Optional[QgsMaskIdProvider]

maskPainter(self, id: int = 0) QPainter | None

Returns a mask QPainter for the render operation. Multiple mask painters can be defined, each with a unique identifier. None is returned if a mask painter with the given identifier does not exist. This is currently used to implement selective masking.

See also

setMaskPainter()

See also

currentMaskId()

Added in version 3.12.

Parameters:

id (int = 0)

Return type:

Optional[QPainter]

outputSize(self) QSize

Returns the size of the resulting rendered image, in pixels.

See also

setOutputSize()

Added in version 3.22.

Return type:

QSize

painter(self) QPainter | None

Returns the destination QPainter for the render operation.

See also

setPainter()

Return type:

Optional[QPainter]

pathResolver(self) QgsPathResolver

Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.

Return type:

QgsPathResolver

previewRenderPainter(self) QPainter | None

Returns the const destination QPainter for temporary in-progress preview renders.

May be None if temporary in-progress preview renders are not required.

Added in version 3.34.

Return type:

Optional[QPainter]

renderedFeatureHandlers(self) List[QgsRenderedFeatureHandlerInterface]

Returns the list of rendered feature handlers to use while rendering map layers.

Added in version 3.10.

Return type:

List[QgsRenderedFeatureHandlerInterface]

rendererScale(self) float

Returns the renderer map scale. This will match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.

Return type:

float

rendererUsage(self) Qgis.RendererUsage

Returns the renderer usage

Added in version 3.24.

Return type:

Qgis.RendererUsage

renderingStopped(self) bool

Returns True if the rendering operation has been stopped and any ongoing rendering should be canceled immediately.

Note

Since QGIS 3.22 the feedback() member exists as an alternative means of cancellation support.

See also

feedback()

Return type:

bool

scaleFactor(self) float

Returns the scaling factor for the render to convert painter units to physical sizes. This is usually equal to the number of pixels per millimeter.

See also

setScaleFactor()

Return type:

float

segmentationTolerance(self) float

Gets the segmentation tolerance applied when rendering curved geometries

Return type:

float

segmentationToleranceType(self) QgsAbstractGeometry.SegmentationToleranceType

Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

Return type:

QgsAbstractGeometry.SegmentationToleranceType

selectionColor(self) QColor

Returns the color to use when rendering selected features.

Return type:

QColor

setCoordinateTransform(self, t: QgsCoordinateTransform)

Sets the current coordinate transform for the context.

This represents the coordinate transform required to transform the layer which is being rendered back to the CRS of the rendered map.

Set to an invalid QgsCoordinateTransform to indicate that no transformation is required.

Parameters:

t (QgsCoordinateTransform)

setCurrentFrame(self, frame: int)

Sets the current frame of the map, for maps which are part of an animation.

Defaults to -1 if the map is not associated with an animation.

See also

currentFrame()

Added in version 3.26.

Parameters:

frame (int)

setCurrentMaskId(self, id: int)

Stores a mask id as the “current” one.

See also

currentMaskId()

Added in version 3.12.

Parameters:

id (int)

setCustomRenderingFlag(self, flag: str | None, value: Any)

Sets a custom rendering flag. Layers might honour these to alter their rendering.

Parameters:
  • flag (Optional[str]) – the flag name

  • value (Any) – the flag value

Added in version 3.12.

setDevicePixelRatio(self, ratio: float)

Sets the device pixel ratio.

Common values are 1 for normal-dpi displays and 2 for high-dpi “retina” displays.

Added in version 3.22.

Parameters:

ratio (float)

setDisabledSymbolLayers(self, symbolLayers: Iterable[QgsSymbolLayer])

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

Sets the list of disabled symbol layers.

Added in version 3.12.

Deprecated since version QGIS: 3.30 and replaced with setDisabledSymbolLayersV2

Parameters:

symbolLayers (Iterable[QgsSymbolLayer])

setDisabledSymbolLayersV2(self, symbolLayers: Iterable[str | None])

When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.

Sets the list of disabled symbol layer ids.

Added in version 3.30.

Parameters:

symbolLayers (Iterable[Optional[str]])

setDistanceArea(self, distanceArea: QgsDistanceArea)

A general purpose distance and area calculator, capable of performing ellipsoid based calculations. Will be used to convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits

Parameters:

distanceArea (QgsDistanceArea)

setDpiTarget(self, dpi: float)

Sets the targeted dpi for rendering.

See also

dpiTarget()

Added in version 3.20.

Parameters:

dpi (float)

setDrawEditingInformation(self, b: bool)

Sets whether edit markers should be drawn during the render operation.

Parameters:

b (bool)

setElevationMap(self, map: QgsElevationMap | None)

Sets the destination elevation map for the render operation. Ownership of the elevation map is not transferred and the QgsElevationMap destination must stay alive for the duration of any rendering operations.

See also

elevationMap()

Added in version 3.30.

Parameters:

map (Optional[QgsElevationMap])

setExpressionContext(self, context: QgsExpressionContext)

Sets the expression context. This context is used for all expression evaluation associated with this render context.

Parameters:

context (QgsExpressionContext)

setExtent(self, extent: QgsRectangle)

When rendering a map layer, calling this method sets the “clipping” extent for the layer (in the layer’s CRS).

This extent should be a “worst-case” scenario, which is guaranteed to completely cover the entire visible portion of the layer when it is rendered to the map. It may be larger than the actual visible area, but MUST contain at least the entire visible area.

See also

setExtent()

See also

setMapExtent()

Parameters:

extent (QgsRectangle)

setFeatureClipGeometry(self, geometry: QgsGeometry)

Sets a geometry to use to clip features at render time.

Note

This is not usually set directly, but rather specified by calling QgsMapSettings:addClippingRegion() prior to constructing a QgsRenderContext.

Added in version 3.16.

Parameters:

geometry (QgsGeometry)

setFeatureFilterProvider(self, ffp: QgsFeatureFilterProvider | None)

Set a filter feature provider used for additional filtering of rendered features.

Parameters:

ffp (Optional[QgsFeatureFilterProvider]) – the filter feature provider

setFeedback(self, feedback: QgsFeedback | None)

Attach a feedback object that can be queried regularly during rendering to check if rendering should be canceled.

Ownership of feedback is NOT transferred, and the caller must take care that it exists for the lifetime of the render context.

See also

feedback()

Added in version 3.22.

Parameters:

feedback (Optional[QgsFeedback])

setFlag(self, flag: Qgis.RenderContextFlag, on: bool = True)

Enable or disable a particular flag (other flags are not affected)

Parameters:
setFlags(self, flags: Qgis.RenderContextFlags | Qgis.RenderContextFlag)

Set combination of flags that will be used for rendering.

Parameters:

flags (Union[Qgis.RenderContextFlags)

setForceVectorOutput(self, force: bool)

Sets whether rendering operations should use vector operations instead of any faster raster shortcuts.

Parameters:

force (bool)

setFrameRate(self, rate: float)

Sets the frame rate of the map (in frames per second), for maps which are part of an animation.

Defaults to -1 if the map is not associated with an animation.

See also

frameRate()

Added in version 3.26.

Parameters:

rate (float)

setGeometry(self, geometry: QgsAbstractGeometry | None)

Sets pointer to original (unsegmentized) geometry

Parameters:

geometry (Optional[QgsAbstractGeometry])

setImageFormat(self, format: QImage.Format)

Sets QImage format which should be used for QImages created during rendering.

See also

imageFormat()

Added in version 3.22.

Parameters:

format (QImage.Format)

setIsGuiPreview(self, preview: bool)

Sets GUI preview mode. GUI preview mode is used to change the behavior of some renderings when they are done to preview of symbology in the GUI. This is especially used to display mask symbol layers rather than painting them in a mask painter, which is not meant to be visible, by definition.

See also

isGuiPreview()

Added in version 3.12.

Parameters:

preview (bool)

setMapExtent(self, extent: QgsRectangle)

Sets the original extent of the map being rendered.

Unlike setExtent(), this extent is always in the final destination CRS for the map render and represents the exact bounds of the map being rendered.

See also

mapExtent()

See also

setExtent()

Added in version 3.4.8.

Parameters:

extent (QgsRectangle)

setMapToPixel(self, mtp: QgsMapToPixel)

Sets the context’s map to pixel transform, which transforms between map coordinates and device coordinates.

See also

mapToPixel()

Parameters:

mtp (QgsMapToPixel)

setMaskIdProvider(self, provider: QgsMaskIdProvider | None)

Attaches a mask id provider to the context. It will allow some rendering operations to set the current mask id based on the context (label layer names and label rules for instance).

See also

maskIdProvider()

Added in version 3.12.

Parameters:

provider (Optional[QgsMaskIdProvider])

setMaskPainter(self, p: QPainter | None, id: int = 0)

Sets a mask QPainter for the render operation. Ownership of the painter is not transferred and the QPainter must stay alive for the duration of any rendering operations. Multiple mask painters can be defined and the second parameter gives a unique identifier to each one.

See also

maskPainter()

Parameters:
  • p (Optional[QPainter])

  • id (int = 0)

setOutputSize(self, size: QSize)

Sets the size of the resulting rendered image, in pixels.

See also

outputSize()

Added in version 3.22.

Parameters:

size (QSize)

setPainter(self, p: QPainter | None)

Sets the destination QPainter for the render operation. Ownership of the painter is not transferred and the QPainter destination must stay alive for the duration of any rendering operations.

See also

painter()

Parameters:

p (Optional[QPainter])

setPainterFlagsUsingContext(self, painter: QPainter | None = None)

Sets relevant flags on a destination painter, using the flags and settings currently defined for the render context.

If no painter is specified, then the flags will be applied to the render context’s painter().

Added in version 3.16.

Parameters:

painter (Optional[QPainter] = None)

setPathResolver(self, resolver: QgsPathResolver)

Sets the path resolver for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.

See also

pathResolver()

Parameters:

resolver (QgsPathResolver)

setPreviewRenderPainter(self, painter: QPainter | None)

Sets the destination painter for temporary in-progress preview renders. Ownership of painter is not transferred and the QPainter destination must stay alive for the duration of any rendering operations.

painter may be None if temporary in-progress preview renders are not required.

Added in version 3.34.

Parameters:

painter (Optional[QPainter])

setRendererScale(self, scale: float)

Sets the renderer map scale. This should match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.

See also

rendererScale()

Parameters:

scale (float)

setRendererUsage(self, usage: Qgis.RendererUsage)

Sets the renderer usage

Note

This usage not alter how the map gets rendered but the intention is that data provider knows the context of rendering and may report that to the backend.

See also

rendererUsage()

Added in version 3.24.

Parameters:

usage (Qgis.RendererUsage)

setRenderingStopped(self, stopped: bool)

Sets whether the rendering operation has been stopped and any ongoing rendering should be canceled immediately.

Note

Since QGIS 3.22 the feedback() member exists as an alternative means of cancellation support.

See also

feedback()

See also

setFeedback()

Parameters:

stopped (bool)

setScaleFactor(self, factor: float)

Sets the scaling factor for the render to convert painter units to physical sizes. This should usually be equal to the number of pixels per millimeter.

See also

scaleFactor()

Parameters:

factor (float)

setSegmentationTolerance(self, tolerance: float)

Sets the segmentation tolerance applied when rendering curved geometries

Parameters:

tolerance (float) – the segmentation tolerance

setSegmentationToleranceType(self, type: QgsAbstractGeometry.SegmentationToleranceType)

Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

Parameters:

type (QgsAbstractGeometry.SegmentationToleranceType) – the segmentation tolerance typename

setSelectionColor(self, color: QColor | Qt.GlobalColor)

Sets the color to use when rendering selected features.

See also

selectionColor()

Parameters:

color (Union[QColor)

setShowSelection(self, showSelection: bool)

Sets whether vector selections should be shown in the rendered map

Parameters:

showSelection (bool) – set to True if selections should be shown

See also

showSelection()

Added in version 2.4.

setSymbologyReferenceScale(self, scale: float)

Sets the symbology reference scale.

This should match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render. Set to -1 to disable symbology scaling by reference scale.

The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if scale is set to 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.

See also

rendererScale()

Added in version 3.22.

Parameters:

scale (float)

setTextRenderFormat(self, format: Qgis.TextRenderFormat)

Sets the text render format, which dictates how text is rendered (e.g. as paths or real text objects).

Added in version 3.4.3.

Parameters:

format (Qgis.TextRenderFormat)

setTextureOrigin(self, origin: QPointF | QPoint)

Sets the texture origin, which should be used as a brush transform when rendering using QBrush objects.

See also

textureOrigin()

Added in version 3.16.

Parameters:

origin (Union[QPointF)

setTransformContext(self, context: QgsCoordinateTransformContext)

Sets the context’s coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

Parameters:

context (QgsCoordinateTransformContext)

setUseAdvancedEffects(self, enabled: bool)

Used to enable or disable advanced effects such as blend modes

Parameters:

enabled (bool)

setUseRenderingOptimization(self, enabled: bool)

Sets whether the rendering optimization (geometry simplification) should be executed

Parameters:

enabled (bool)

setVectorSimplifyMethod(self, simplifyMethod: QgsVectorSimplifyMethod)

Sets the simplification setting to use when rendering vector layers.

This can be used to specify simplification methods to apply during map exports and renders, e.g. to allow vector layers to be simplified to an appropriate maximum level of detail during PDF exports or to speed up layer rendering

The default is to use no simplification.

Parameters:

simplifyMethod (QgsVectorSimplifyMethod)

setZRange(self, range: QgsDoubleRange)

Sets the range of z-values which should be rendered.

See also

zRange()

Added in version 3.18.

Parameters:

range (QgsDoubleRange)

showSelection(self) bool

Returns True if vector selections should be shown in the rendered map

Return type:

bool

Returns:

True if selections should be shown

See also

selectionColor()

Added in version 2.4.

symbolLayerClipGeometries(self, symbolLayerId: str | None) List[QgsGeometry]

Returns clipping geometries to be applied to the symbolLayer before rendering

Added in version 3.38.

Parameters:

symbolLayerId (Optional[str])

Return type:

List[QgsGeometry]

symbolLayerClipPaths(self, symbolLayerId: str | None) List[QPainterPath]

Returns clip paths to be applied to the symbolLayer before rendering

Added in version 3.26.

Parameters:

symbolLayerId (Optional[str])

Return type:

List[QPainterPath]

symbologyReferenceScale(self) float

Returns the symbology reference scale.

This represents the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render. A value of -1 indicates that symbology scaling by reference scale is disabled.

The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if the scale is 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.

See also

rendererScale()

Added in version 3.22.

Return type:

float

testFlag(self, flag: Qgis.RenderContextFlag) bool

Check whether a particular flag is enabled.

Parameters:

flag (Qgis.RenderContextFlag)

Return type:

bool

textRenderFormat(self) Qgis.TextRenderFormat

Returns the text render format, which dictates how text is rendered (e.g. as paths or real text objects).

Added in version 3.4.3.

Return type:

Qgis.TextRenderFormat

textureOrigin(self) QPointF

Returns the texture origin, which should be used as a brush transform when rendering using QBrush objects.

Added in version 3.16.

Return type:

QPointF

transformContext(self) QgsCoordinateTransformContext

Returns the context’s coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

Return type:

QgsCoordinateTransformContext

useAdvancedEffects(self) bool

Returns True if advanced effects such as blend modes such be used

Return type:

bool

useRenderingOptimization(self) bool

Returns True if the rendering optimization (geometry simplification) can be executed

Return type:

bool

vectorSimplifyMethod(self) QgsVectorSimplifyMethod

Returns the simplification settings to use when rendering vector layers.

The default is to use no simplification.

Return type:

QgsVectorSimplifyMethod

zRange(self) QgsDoubleRange

Returns the range of z-values which should be rendered.

See also

setZRange()

Added in version 3.18.

Return type:

QgsDoubleRange