Class: QgsPainting

Contains miscellaneous painting utility functions.

Enums

BlendMode

Blending modes defining the available composition modes that can be used when painting.

Static Methods

applyScaleFixForQPictureDpi

Applies a workaround to a painter to avoid an issue with incorrect scaling when drawing QPictures.

drawPicture

Draws a picture onto a painter, correctly applying workarounds to avoid issues with incorrect scaling.

drawTriangleUsingTexture

Draws a triangle onto a painter using a mapped texture image.

getBlendModeEnum

Returns a Qgis.BlendMode corresponding to a QPainter.CompositionMode.

getCompositionMode

Returns a QPainter.CompositionMode corresponding to a Qgis.BlendMode.

isClippingMode

Returns True if mode is a clipping blend mode.

qtDefaultDpiX

Returns the default Qt horizontal DPI.

qtDefaultDpiY

Returns the default Qt vertical DPI.

triangleToTriangleTransform

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: IntEnum

Blending 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: Normal

    Available as QgsPainting.BlendNormal in older QGIS releases.

  • Lighten: Lighten

    Available as QgsPainting.BlendLighten in older QGIS releases.

  • Screen: Screen

    Available as QgsPainting.BlendScreen in older QGIS releases.

  • Dodge: Dodge

    Available as QgsPainting.BlendDodge in older QGIS releases.

  • Addition: Addition

    Available as QgsPainting.BlendAddition in older QGIS releases.

  • Darken: Darken

    Available as QgsPainting.BlendDarken in older QGIS releases.

  • Multiply: Multiple

    Available as QgsPainting.BlendMultiply in older QGIS releases.

  • Burn: Burn

    Available as QgsPainting.BlendBurn in older QGIS releases.

  • Overlay: Overlay

    Available as QgsPainting.BlendOverlay in older QGIS releases.

  • SoftLight: Soft light

    Available as QgsPainting.BlendSoftLight in older QGIS releases.

  • HardLight: Hard light

    Available as QgsPainting.BlendHardLight in older QGIS releases.

  • Difference: Difference

    Available as QgsPainting.BlendDifference in older QGIS releases.

  • Subtract: Subtract

    Available as QgsPainting.BlendSubtract in older QGIS releases.

  • Source: Source

    Available as QgsPainting.BlendSource in older QGIS releases.

  • DestinationOver: Destination over

    Available as QgsPainting.BlendDestinationOver in older QGIS releases.

  • Clear: Clear

    Available as QgsPainting.BlendClear in older QGIS releases.

  • Destination: Destination

    Available as QgsPainting.BlendDestination in older QGIS releases.

  • SourceIn: Source in

    Available as QgsPainting.BlendSourceIn in older QGIS releases.

  • DestinationIn: Destination in

    Available as QgsPainting.BlendDestinationIn in older QGIS releases.

  • SourceOut: Source out

    Available as QgsPainting.BlendSourceOut in older QGIS releases.

  • DestinationOut: Destination out

    Available as QgsPainting.BlendDestinationOut in older QGIS releases.

  • SourceAtop: Source atop

    Available as QgsPainting.BlendSourceAtop in older QGIS releases.

  • DestinationAtop: Destination atop

    Available as QgsPainting.BlendDestinationAtop in older QGIS releases.

  • Xor: XOR

    Available as QgsPainting.BlendXor in older QGIS releases.

static applyScaleFixForQPictureDpi(painter: QPainter | None)[source]

Applies a workaround to a painter to avoid an issue with incorrect scaling when drawing QPictures.

Note

This is a low-level method, which alters the painter state and relies on the caller saving/restoring painter state accordingly. Consider using the high-level drawPicture() method instead.

See also

drawPicture()

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.

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 triangle onto a painter using 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 triangle is a closed QPolygonF consisting of 4 vertices (the 3 triangle vertices + the first vertex again to close the polygon).

Returns True if the triangle could be rendered, or False if 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.

Parameters:

blendMode (QPainter.CompositionMode)

Return type:

Qgis.BlendMode

static getCompositionMode(blendMode: Qgis.BlendMode) QPainter.CompositionMode[source]

Returns a QPainter.CompositionMode corresponding to a Qgis.BlendMode.

Parameters:

blendMode (Qgis.BlendMode)

Return type:

QPainter.CompositionMode

static isClippingMode(mode: Qgis.BlendMode) bool[source]

Returns True if mode is 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

qtDefaultDpiY()

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

qtDefaultDpiX()

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: True if the transform could be determined.

Added in version 3.34.