Class: QgsEffectStack

class qgis.core.QgsEffectStack

Bases: QgsPaintEffect

Constructor for empty QgsEffectStack.

QgsEffectStack(other: QgsEffectStack)

QgsEffectStack(effect: QgsPaintEffect) Creates a new QgsEffectStack effect from a single initial effect.

Parameters

effect – initial effect to add to the stack. The effect will be cloned, so ownership is not transferred to the stack.

Returns

new QgsEffectStack containing initial effect

A paint effect which consists of a stack of other chained paint effects

Effect stacks can be used to apply multiple paint effects to a QPicture. For instance, an effect stack may blur then apply a drop shadow.

The way in which effects apply to a stack is controlled by the effect’s drawMode. Effects can either render their results onto the destination paint device, or just modify the source picture which is drawn by subsequent effects in the stack. For instance, a blur effect with a Modifier drawMode will blur the source picture for the following drop shadow effect without actually drawing the blurred picture to the paint device. If the blur effect had a Render drawMode then the blurred picture will be drawn on the paint device, but the following drop shadow effect will be drawn using the original picture, not the blurred version.

Methods

appendEffect

Appends an effect to the end of the stack.

boundingRect

Returns the bounding rect required for drawing the effect.

changeEffect

Replaces the effect at a specified position within the stack.

clone

rtype

QgsEffectStack

count

Returns count of effects contained by the stack

create

Creates a new QgsEffectStack effect.

draw

param context

drawSource

Draws the source QPicture onto the specified painter.

effect

Returns a pointer to the effect at a specified index within the stack

effectList

Returns a pointer to the list of effects currently contained by the stack

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.

insertEffect

Inserts an effect at a specified index within the stack.

properties

Unused for QgsEffectStack, will always return an empty string map

readProperties

readProperties(self, props: Dict[str, Any]) Unused for QgsEffectStack, props parameter will be ignored

saveProperties

param doc

source

Returns the source QPicture.

sourceAsImage

Returns the source QPicture rendered to a new QImage.

takeEffect

Removes an effect from the stack and returns a pointer to it.

type

rtype

str

appendEffect(self, effect: QgsPaintEffect)

Appends an effect to the end of the stack.

Parameters

effect (QgsPaintEffect) – QgsPaintEffect to append. Ownership of the effect will be transferred to the stack object.

See also

insertEffect()

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()

changeEffect(self, index: int, effect: QgsPaintEffect) → bool

Replaces the effect at a specified position within the stack.

Parameters
  • index (int) – position of effect to replace

  • effect (QgsPaintEffect) – QgsPaintEffect to replace with. Ownership of the effect will be transferred to the stack object.

Return type

bool

clone(self)QgsEffectStack
Return type

QgsEffectStack

count(self) → int

Returns count of effects contained by the stack

Return type

int

Returns

count of effects

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

Creates a new QgsEffectStack effect. This method ignores the map parameter, and always returns an empty effect stack.

Parameters

map (Dict[str) – unused encoded properties string map

Return type

QgsPaintEffect

Returns

new QgsEffectStack

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()

effect(self, index: int)QgsPaintEffect

Returns a pointer to the effect at a specified index within the stack

Parameters

index (int) – position of effect to return

Return type

QgsPaintEffect

Returns

QgsPaintEffect at specified position

effectList(self) → List[QgsPaintEffect]

Returns a pointer to the list of effects currently contained by the stack

Return type

List[QgsPaintEffect]

Returns

list of QgsPaintEffects within the stack

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()

insertEffect(self, index: int, effect: QgsPaintEffect) → bool

Inserts an effect at a specified index within the stack.

Parameters
  • index (int) – position to insert the effect

  • effect (QgsPaintEffect) – QgsPaintEffect to insert. Ownership of the effect will be transferred to the stack object.

See also

appendEffect()

Return type

bool

properties(self) → Dict[str, Any]

Unused for QgsEffectStack, will always return an empty string map

Return type

Dict[str, Any]

readProperties(self, element: QDomElement) → bool

readProperties(self, props: Dict[str, Any]) Unused for QgsEffectStack, props parameter will be ignored

Parameters

element (QDomElement) –

Return type

bool

saveProperties(self, doc: QDomDocument, element: QDomElement) → bool
Parameters
  • doc (QDomDocument) –

  • element (QDomElement) –

Return type

bool

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()

takeEffect(self, index: int)QgsPaintEffect

Removes an effect from the stack and returns a pointer to it.

Parameters

index (int) – position of effect to take

Return type

QgsPaintEffect

type(self) → str
Return type

str