Class: QgsPainting¶
Contains miscellaneous painting utility functions.
Enums
Blending modes defining the available composition modes that can be used when painting.  | 
Static Methods
Applies a workaround to a painter to avoid an issue with incorrect scaling when drawing QPictures.  | 
|
Draws a picture onto a painter, correctly applying workarounds to avoid issues with incorrect scaling.  | 
|
Draws a triangle onto a painter using a mapped texture image.  | 
|
Returns a   | 
|
Returns a QPainter.CompositionMode corresponding to a   | 
|
Returns   | 
|
Returns the default Qt horizontal DPI.  | 
|
Returns the default Qt vertical DPI.  | 
|
Calculates the QTransform which maps the triangle defined by the points (inX1, inY1), (inY2, inY2), (inX3, inY3) to the triangle defined by (outX1, outY1), (outY2, outY2), (outX3, outY3).  | 
- class qgis.core.QgsPainting[source]¶
 Bases:
object- class BlendMode(*values)¶
 Bases:
IntEnumBlending modes defining the available composition modes that can be used when painting.
Note
Prior to QGIS 3.30 this was available as
QgsPainting.BlendMode.Added in version 3.30.
Normal: NormalAvailable as
QgsPainting.BlendNormalin older QGIS releases.Lighten: LightenAvailable as
QgsPainting.BlendLightenin older QGIS releases.Screen: ScreenAvailable as
QgsPainting.BlendScreenin older QGIS releases.Dodge: DodgeAvailable as
QgsPainting.BlendDodgein older QGIS releases.Addition: AdditionAvailable as
QgsPainting.BlendAdditionin older QGIS releases.Darken: DarkenAvailable as
QgsPainting.BlendDarkenin older QGIS releases.Multiply: MultipleAvailable as
QgsPainting.BlendMultiplyin older QGIS releases.Burn: BurnAvailable as
QgsPainting.BlendBurnin older QGIS releases.Overlay: OverlayAvailable as
QgsPainting.BlendOverlayin older QGIS releases.SoftLight: Soft lightAvailable as
QgsPainting.BlendSoftLightin older QGIS releases.HardLight: Hard lightAvailable as
QgsPainting.BlendHardLightin older QGIS releases.Difference: DifferenceAvailable as
QgsPainting.BlendDifferencein older QGIS releases.Subtract: SubtractAvailable as
QgsPainting.BlendSubtractin older QGIS releases.Source: SourceAvailable as
QgsPainting.BlendSourcein older QGIS releases.DestinationOver: Destination overAvailable as
QgsPainting.BlendDestinationOverin older QGIS releases.Clear: ClearAvailable as
QgsPainting.BlendClearin older QGIS releases.Destination: DestinationAvailable as
QgsPainting.BlendDestinationin older QGIS releases.SourceIn: Source inAvailable as
QgsPainting.BlendSourceInin older QGIS releases.DestinationIn: Destination inAvailable as
QgsPainting.BlendDestinationInin older QGIS releases.SourceOut: Source outAvailable as
QgsPainting.BlendSourceOutin older QGIS releases.DestinationOut: Destination outAvailable as
QgsPainting.BlendDestinationOutin older QGIS releases.SourceAtop: Source atopAvailable as
QgsPainting.BlendSourceAtopin older QGIS releases.DestinationAtop: Destination atopAvailable as
QgsPainting.BlendDestinationAtopin older QGIS releases.Xor: XORAvailable as
QgsPainting.BlendXorin older QGIS releases.
- static applyScaleFixForQPictureDpi(painter: QPainter | None)[source]¶
 Applies a workaround to a
painterto avoid an issue with incorrect scaling when drawing QPictures.Note
This is a low-level method, which alters the
painterstate and relies on the caller saving/restoring painter state accordingly. Consider using the high-leveldrawPicture()method instead.See also
Added in version 3.40.
- Parameters:
 painter (Optional[QPainter])
- static drawPicture(painter: QPainter | None, point: QPointF | QPoint, picture: QPicture)[source]¶
 Draws a picture onto a
painter, correctly applying workarounds to avoid issues with incorrect scaling.See also
Added in version 3.40.
- Parameters:
 painter (Optional[QPainter])
point (Union[QPointF, QPoint])
picture (QPicture)
- static drawTriangleUsingTexture(painter: QPainter | None, triangle: QPolygonF, textureImage: QImage, textureX1: float, textureY1: float, textureX2: float, textureY2: float, textureX3: float, textureY3: float) bool[source]¶
 Draws a
triangleonto apainterusing a mapped texture image.The triangle will be rendered using the portion of the texture image described by the triangle (
textureX1,textureY1), (textureX2,textureY2), (textureX3,textureY3). Texture coordinates should be in the range 0-1 (as a fraction of the image size), where (0, 0) coorresponds to the top-left of the texture image.The caller must ensure that
triangleis a closed QPolygonF consisting of 4 vertices (the 3 triangle vertices + the first vertex again to close the polygon).Returns
Trueif the triangle could be rendered, orFalseif it could not (e.g. when the described points are co-linear).Added in version 3.34.
- Parameters:
 painter (Optional[QPainter])
triangle (QPolygonF)
textureImage (QImage)
textureX1 (float)
textureY1 (float)
textureX2 (float)
textureY2 (float)
textureX3 (float)
textureY3 (float)
- Return type:
 bool
- static getBlendModeEnum(blendMode: QPainter.CompositionMode) Qgis.BlendMode[source]¶
 Returns a
Qgis.BlendMode corresponding to a QPainter.CompositionMode.See also
- Parameters:
 blendMode (QPainter.CompositionMode)
- Return type:
 
- static getCompositionMode(blendMode: Qgis.BlendMode) QPainter.CompositionMode[source]¶
 Returns a QPainter.CompositionMode corresponding to a
Qgis.BlendMode.See also
- Parameters:
 blendMode (Qgis.BlendMode)
- Return type:
 QPainter.CompositionMode
- static isClippingMode(mode: Qgis.BlendMode) bool[source]¶
 Returns
Trueifmodeis a clipping blend mode.Added in version 3.30.
- Parameters:
 mode (Qgis.BlendMode)
- Return type:
 bool
- static qtDefaultDpiX() int[source]¶
 Returns the default Qt horizontal DPI.
Note
This method proxies the internal Qt
qt_defaultDpiX()function.See also
Added in version 3.40.
- Return type:
 int
- static qtDefaultDpiY() int[source]¶
 Returns the default Qt vertical DPI.
Note
This method proxies the internal Qt
qt_defaultDpiY()function.See also
Added in version 3.40.
- Return type:
 int
- static triangleToTriangleTransform(inX1: float, inY1: float, inX2: float, inY2: float, inX3: float, inY3: float, outX1: float, outY1: float, outX2: float, outY2: float, outX3: float, outY3: float)[source]¶
 Calculates the QTransform which maps the triangle defined by the points (
inX1,inY1), (inY2,inY2), (inX3,inY3) to the triangle defined by (outX1,outY1), (outY2,outY2), (outX3,outY3).- Parameters:
 inX1 (float) – source triangle vertex 1 x-coordinate
inY1 (float) – source triangle vertex 1 y-coordinate
inX2 (float) – source triangle vertex 2 x-coordinate
inY2 (float) – source triangle vertex 2 y-coordinate
inX3 (float) – source triangle vertex 3 x-coordinate
inY3 (float) – source triangle vertex 3 y-coordinate
outX1 (float) – destination triangle vertex 1 x-coordinate
outY1 (float) – destination triangle vertex 1 y-coordinate
outX2 (float) – destination triangle vertex 2 x-coordinate
outY2 (float) – destination triangle vertex 2 y-coordinate
outX3 (float) – destination triangle vertex 3 x-coordinate
outY3 (float) -> (QTransform) – destination triangle vertex 3 y-coordinate
- Returns:
 Calculated transform (if possible)
ok:
Trueif the transform could be determined.
Added in version 3.34.