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
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: clone()
, draw()
, properties()
, readProperties()
, type()
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 alterations. |
|
Base class for paint effects which render offset, blurred shadows. |
|
A paint effect which consists of a stack of other chained paint effects. |
|
Base class for paint effects which draw a glow inside or outside a picture. |
|
A paint effect which applies transformations (such as move, scale and rotate) to a picture. |
Abstract Methods
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 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. |
|
Returns the effect type. |
Methods
Returns the draw mode for the effect. |
|
Draws the source QPicture onto the specified painter. |
|
Returns whether the effect is enabled |
|
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. |
|
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. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsPaintEffect. See the FAQ for more details.
Begins intercepting paint operations to a render context. |
|
Returns the bounding rect required for drawing the effect. |
|
Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect. |
|
Returns flags which specify how the paint effect behaves. |
|
Renders a picture using the effect. |
|
Saves the current state of the effect to a DOM element. |
Attributes
- class qgis.core.QgsPaintEffect[source]¶
Bases:
object
- class DrawMode¶
Bases:
int
- Modifier = 0¶
- ModifyAndRender = 2¶
- Render = 1¶
- virtual 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
- virtual 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
- abstract 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
- abstract 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
- virtual 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.
- virtual flags(self) Qgis.PaintEffectFlags [source]¶
Returns flags which specify how the paint effect behaves.
Added in version 3.44.
- Return type:
- 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
- abstract 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
- abstract 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
- abstract 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
- virtual 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
- virtual 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)