Class: QgsPaintEffect¶
- class qgis.core.QgsPaintEffect¶
Bases:
sip.wrapper
Base class for visual effects which can be applied to QPicture drawings
QgsPaintEffect
objects can be used to modify QPicture drawings prior to rendering them with a QPainter operation. There are two methods for drawing using an effect, either drawing a picture directly, or by intercepting drawing operations to a render context.To directly draw a picture, use the
render()
method with a source QPicture and destination render context.Intercepting drawing operations to a render context is achieved by first calling the
begin()
method, passing a render context. Any drawing operations performed on the render context will not directly affect the context’s paint device. When the drawing operations have been completed, call theend()
method. This will perform the paint effect on the intercepted drawing operations and render the result to the render context’s paint device.See also
QgsPaintEffect() Constructor for QgsPaintEffect.
QgsPaintEffect(other:
QgsPaintEffect
)Methods
Begins intercepting paint operations to a render context.
Returns the bounding rect required for drawing the effect.
Duplicates an effect by creating a deep copy of the effect
Handles drawing of the effect's result on to the specified render context.
Returns the draw mode for the effect.
Draws the source QPicture onto the specified painter.
Returns whether the effect is enabled
Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect.
Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.
Returns the offset which should be used when drawing the source image on to a destination render context.
Returns the properties describing the paint effect encoded in a string format.
Reads a string map of an effect's properties and restores the effect to the state described by the properties map.
Renders a picture using the effect.
Saves the current state of the effect to a DOM element.
Sets the draw mode for the effect.
Sets whether the effect is enabled
Returns the source QPicture.
Returns the source QPicture rendered to a new QImage.
Returns the effect type.
Attributes
- class DrawMode¶
Bases:
int
- Modifier = 0¶
- ModifyAndRender = 2¶
- Render = 1¶
- begin(self, context: QgsRenderContext)¶
Begins intercepting paint operations to a render context. When the corresponding
end()
member is called all intercepted paint operations will be drawn to the render context after being modified by the effect.- Parameters:
context (QgsRenderContext) – destination render context
See also
See also
- 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 (QRectF) – original source bounding rect
context (QgsRenderContext) – destination render context
- Return type:
QRectF
- Returns:
modified bounding rect
See also
- clone(self) QgsPaintEffect ¶
Duplicates an effect by creating a deep copy of the effect
- Return type:
- Returns:
clone of paint effect
- draw(self, context: QgsRenderContext)¶
Handles drawing of the effect’s result on to the specified render context. Derived classes must reimplement this method to apply any transformations to the source QPicture and draw the result using the context’s painter.
- Parameters:
context (QgsRenderContext) – destination render context
See also
- drawMode(self) QgsPaintEffect.DrawMode ¶
Returns the draw mode for the effect. This property only has an effect if the paint effect is used in a
QgsEffectStack
.- Return type:
- Returns:
draw mode for effect
See also
- 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 (QPainter) – destination painter
See also
See also
- enabled(self) bool ¶
Returns whether the effect is enabled
- Return type:
bool
- Returns:
True
if effect is enabled
See also
- end(self, context: QgsRenderContext)¶
Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect.
- Parameters:
context (QgsRenderContext) – destination render context
See also
- 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 (QPainter) – 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 (QgsRenderContext) – destination render context
- Return type:
QPointF
- Returns:
point offset for image top left corner
See also
- properties(self) Dict[str, Any] ¶
Returns the properties describing the paint effect encoded in a string format.
- Return type:
Dict[str, Any]
- Returns:
string map of properties, in the form property key, value
See also
See also
- readProperties(self, props: Dict[str, Any])¶
Reads a string map of an effect’s properties and restores the effect to the state described by the properties map.
- Parameters:
props (Dict[str) – effect properties encoded in a string map
See also
readProperties(self, element: QDomElement) -> bool Restores the effect to the state described by a DOM element.
- Parameters:
element – DOM element describing an effect’s state
- Returns:
True
if read was successful
See also
- render(self, picture: QPicture, context: QgsRenderContext)¶
Renders a picture using the effect.
- Parameters:
picture (QPicture) – source QPicture to render
context (QgsRenderContext) – destination render context
See also
- saveProperties(self, doc: QDomDocument, element: QDomElement) bool ¶
Saves the current state of the effect to a DOM element. The default behavior is to save the properties string map returned by
properties()
.- Parameters:
doc (QDomDocument) – destination DOM document
element (QDomElement) – destination DOM element
- Return type:
bool
- Returns:
True
if save was successful
See also
- setDrawMode(self, drawMode: QgsPaintEffect.DrawMode)¶
Sets the draw mode for the effect. This property only has an effect if the paint effect is used in a
QgsEffectStack
.- Parameters:
drawMode (QgsPaintEffect.DrawMode) – draw mode for effect
See also
- setEnabled(self, enabled: bool)¶
Sets whether the effect is enabled
- Parameters:
enabled (bool) – set to
False
to disable the effect
See also
- source(self) QPicture ¶
Returns the source QPicture. The
draw()
member can utilize this when drawing the effect.- Return type:
QPicture
- Returns:
source QPicture
See also
See also
- 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 theboundingRect()
method. The result is cached to speed up subsequent calls to sourceAsImage.- Return type:
QImage
- Returns:
source QPicture rendered to an image
See also
See also
See also
See also
- Parameters:
context (QgsRenderContext) –
- type(self) str ¶
Returns the effect type.
- Return type:
str
- Returns:
unique string representation of the effect type