Class: QgsDrawSourceEffect

class qgis.core.QgsDrawSourceEffect

Bases: QgsPaintEffect

Constructor for QgsDrawSourceEffect

A paint effect which draws the source picture with minor or no alterations

The draw source effect can be used to draw an unaltered copy of the original source picture. Minor changes like lowering the opacity and applying a blend mode are supported, however these changes will force the resultant output to be rasterized. If no alterations are performed then the original picture will be rendered as a vector.

Methods

blendMode

Returns the blend mode for the effect

boundingRect

Returns the bounding rect required for drawing the effect.

clone

rtype

QgsDrawSourceEffect

create

Creates a new QgsDrawSource effect from a properties string map.

draw

param context

drawSource

Draws the source QPicture onto the specified painter.

fixQPictureDpi

Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.

imageOffset

Returns the offset which should be used when drawing the source image on to a destination render context.

opacity

Returns the opacity for the effect

properties

rtype

Dict[str, Any]

readProperties

param props

setBlendMode

Sets the blend mode for the effect

setOpacity

Sets the opacity for the effect.

source

Returns the source QPicture.

sourceAsImage

Returns the source QPicture rendered to a new QImage.

type

rtype

str

blendMode(self) → QPainter.CompositionMode

Returns the blend mode for the effect

Return type

QPainter.CompositionMode

Returns

blend mode used for drawing the source on to a destination paint device

See also

setBlendMode()

boundingRect(self, rect: QRectF, context: QgsRenderContext) → QRectF

Returns the bounding rect required for drawing the effect. This method can be used to expand the bounding rect of a source picture to account for offset or blurring effects.

Parameters
  • rect – original source bounding rect

  • context – destination render context

Returns

modified bounding rect

See also

sourceAsImage()

clone(self)QgsDrawSourceEffect
Return type

QgsDrawSourceEffect

create(map: Dict[str, Any])QgsPaintEffect

Creates a new QgsDrawSource effect from a properties string map.

Parameters

map (Dict[str) – encoded properties string map

Return type

QgsPaintEffect

Returns

new QgsDrawSourceEffect

draw(self, context: QgsRenderContext)
Parameters

context (QgsRenderContext) –

drawSource(self, painter: QPainter)

Draws the source QPicture onto the specified painter. Handles scaling of the picture to account for the destination painter’s DPI.

Parameters

painter – destination painter

See also

source()

See also

sourceAsImage()

fixQPictureDpi(self, painter: QPainter)

Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures. This may need to be called by derived classes prior to rendering results onto a painter.

Parameters

painter – destination painter

imageOffset(self, context: QgsRenderContext) → QPointF

Returns the offset which should be used when drawing the source image on to a destination render context.

Parameters

context – destination render context

Returns

point offset for image top left corner

See also

sourceAsImage()

opacity(self) → float

Returns the opacity for the effect

Return type

float

Returns

opacity value between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque

See also

setOpacity()

properties(self) → Dict[str, Any]
Return type

Dict[str, Any]

readProperties(self, props: Dict[str, Any])
Parameters

props (Dict[str) –

setBlendMode(self, mode: QPainter.CompositionMode)

Sets the blend mode for the effect

Parameters

mode (QPainter.CompositionMode) – blend mode used for drawing the source on to a destination paint device

See also

blendMode()

setOpacity(self, opacity: float)

Sets the opacity for the effect.

Parameters

opacity (float) – double between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque

See also

opacity()

source(self) → QPicture

Returns the source QPicture. The draw() member can utilize this when drawing the effect.

Returns

source QPicture

See also

drawSource()

See also

sourceAsImage()

sourceAsImage(self, context: QgsRenderContext) → QImage

Returns the source QPicture rendered to a new QImage. The draw() member can utilize this when drawing the effect. The image will be padded or cropped from the original source QPicture by the results of the boundingRect() method. The result is cached to speed up subsequent calls to sourceAsImage.

Returns

source QPicture rendered to an image

See also

drawSource()

See also

source()

See also

imageOffset()

See also

boundingRect()

type(self) → str
Return type

str