Class: QgsPaintEffect¶
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 the end()
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
Class Hierarchy¶
Subclasses¶
A paint effect which blurs a source picture, using a number of different blur methods. |
|
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture. |
|
A paint effect which draws the source picture with minor or no |
|
Base class for paint effects which offset, blurred shadows |
|
A paint effect which consists of a stack of other chained paint effects |
|
Base class for paint effect which draw a glow inside or outside a picture. |
|
A paint effect which applies transformations (such as move, scale and rotate) to a picture. |
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 qgis.core.QgsPaintEffect[source]¶
Bases:
object
- class DrawMode¶
Bases:
int
- Modifier = 0¶
- ModifyAndRender = 2¶
- Render = 1¶
- begin(self, context: QgsRenderContext)[source]¶
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 [source]¶
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 | None [source]¶
Duplicates an effect by creating a deep copy of the effect
- Return type:
Optional[QgsPaintEffect]
- Returns:
clone of paint effect
- draw(self, context: QgsRenderContext)[source]¶
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 [source]¶
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)[source]¶
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 [source]¶
Returns whether the effect is enabled
- Return type:
bool
- Returns:
True
if effect is enabled
See also
- end(self, context: QgsRenderContext)[source]¶
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 | None)[source]¶
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 (Optional[QPainter]) – destination painter
Deprecated since version 3.40: Use
QgsPainting.drawPicture()
orQgsPainting.applyScaleFixForQPictureDpi()
instead.
- imageOffset(self, context: QgsRenderContext) QPointF [source]¶
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] [source]¶
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])[source]¶
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, Any]) – effect properties encoded in a string map
See also
- readProperties(self, element: QDomElement) bool [source]
Restores the effect to the state described by a DOM element.
- Parameters:
element (QDomElement) – DOM element describing an effect’s state
- Return type:
bool
- Returns:
True
if read was successful
See also
- render(self, picture: QPicture, context: QgsRenderContext)[source]¶
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 [source]¶
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)[source]¶
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)[source]¶
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 [source]¶
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, or a null image if source could not be rendered
See also
See also
See also
See also
- Parameters:
context (QgsRenderContext)