QPaintEngine#

The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a given platform. More

Inheritance diagram of PySide6.QtGui.QPaintEngine

Synopsis#

Functions#

Virtual functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Qt provides several premade implementations of QPaintEngine for the different painter backends we support. The primary paint engine provided is the raster paint engine, which contains a software rasterizer which supports the full feature set on all supported platforms. This is the default for painting on QWidget -based classes in e.g. on Windows, X11 and macOS, it is the backend for painting on QImage and it is used as a fallback for paint engines that do not support a certain capability. In addition we provide QPaintEngine implementations for OpenGL (accessible through QOpenGLWidget ) and printing (which allows using QPainter to draw on a QPrinter object).

If one wants to use QPainter to draw to a different backend, one must subclass QPaintEngine and reimplement all its virtual functions. The QPaintEngine implementation is then made available by subclassing QPaintDevice and reimplementing the virtual function paintEngine() .

QPaintEngine is created and owned by the QPaintDevice that created it.

class PySide6.QtGui.QPaintEngine([features=QPaintEngine.PaintEngineFeatures()])#
Parameters:

featuresPaintEngineFeatures

Creates a paint engine with the featureset specified by caps.

PySide6.QtGui.QPaintEngine.PaintEngineFeature#

(inherits enum.Flag) This enum is used to describe the features or capabilities that the paint engine has. If a feature is not supported by the engine, QPainter will do a best effort to emulate that feature through other means and pass on an alpha blended QImage to the engine with the emulated results. Some features cannot be emulated: AlphaBlend and PorterDuff.

Constant

Description

QPaintEngine.AlphaBlend

The engine can alpha blend primitives.

QPaintEngine.Antialiasing

The engine can use antialiasing to improve the appearance of rendered primitives.

QPaintEngine.BlendModes

The engine supports blending modes.

QPaintEngine.BrushStroke

The engine supports drawing strokes that contain brushes as fills, not just solid colors (e.g. a dashed gradient line of width 2).

QPaintEngine.ConicalGradientFill

The engine supports conical gradient fills.

QPaintEngine.ConstantOpacity

The engine supports the feature provided by setOpacity() .

QPaintEngine.LinearGradientFill

The engine supports linear gradient fills.

QPaintEngine.MaskedBrush

The engine is capable of rendering brushes that has a texture with an alpha channel or a mask.

QPaintEngine.ObjectBoundingModeGradients

The engine has native support for gradients with coordinate mode ObjectBoundingMode . Otherwise, if QPaintEngine::PatternTransform is supported, object bounding mode gradients are converted to gradients with coordinate mode LogicalMode and a brush transform for the coordinate mapping.

QPaintEngine.PainterPaths

The engine has path support.

QPaintEngine.PaintOutsidePaintEvent

The engine is capable of painting outside of paint events.

QPaintEngine.PatternBrush

The engine is capable of rendering brushes with the brush patterns specified in BrushStyle .

QPaintEngine.PatternTransform

The engine has support for transforming brush patterns.

QPaintEngine.PerspectiveTransform

The engine has support for performing perspective transformations on primitives.

QPaintEngine.PixmapTransform

The engine can transform pixmaps, including rotation and shearing.

QPaintEngine.PorterDuff

The engine supports Porter-Duff operations

QPaintEngine.PrimitiveTransform

The engine has support for transforming drawing primitives.

QPaintEngine.RadialGradientFill

The engine supports radial gradient fills.

QPaintEngine.RasterOpModes

The engine supports bitwise raster operations.

QPaintEngine.AllFeatures

All of the above features. This enum value is usually used as a bit mask.

PySide6.QtGui.QPaintEngine.DirtyFlag#

Constant

Description

QPaintEngine.DirtyPen

(inherits enum.Flag) The pen is dirty and needs to be updated.

QPaintEngine.DirtyBrush

The brush is dirty and needs to be updated.

QPaintEngine.DirtyBrushOrigin

The brush origin is dirty and needs to updated.

QPaintEngine.DirtyFont

The font is dirty and needs to be updated.

QPaintEngine.DirtyBackground

The background is dirty and needs to be updated.

QPaintEngine.DirtyBackgroundMode

The background mode is dirty and needs to be updated.

QPaintEngine.DirtyTransform

The transform is dirty and needs to be updated.

QPaintEngine.DirtyClipRegion

The clip region is dirty and needs to be updated.

QPaintEngine.DirtyClipPath

The clip path is dirty and needs to be updated.

QPaintEngine.DirtyHints

The render hints is dirty and needs to be updated.

QPaintEngine.DirtyCompositionMode

The composition mode is dirty and needs to be updated.

QPaintEngine.DirtyClipEnabled

Whether clipping is enabled or not is dirty and needs to be updated.

QPaintEngine.DirtyOpacity

The constant opacity has changed and needs to be updated as part of the state change in updateState() .

QPaintEngine.AllDirty

Convenience enum used internally.

These types are used by QPainter to trigger lazy updates of the various states in the QPaintEngine using updateState() .

A paint engine must update every dirty state.

PySide6.QtGui.QPaintEngine.PolygonDrawMode#

Constant

Description

QPaintEngine.OddEvenMode

The polygon should be drawn using OddEven fill rule.

QPaintEngine.WindingMode

The polygon should be drawn using Winding fill rule.

QPaintEngine.ConvexMode

The polygon is a convex polygon and can be drawn using specialized algorithms where available.

QPaintEngine.PolylineMode

Only the outline of the polygon should be drawn.

PySide6.QtGui.QPaintEngine.Type#

Constant

Description

QPaintEngine.X11

QPaintEngine.Windows

QPaintEngine.MacPrinter

QPaintEngine.CoreGraphics

macOS’s Quartz2D (CoreGraphics)

QPaintEngine.QuickDraw

macOS’s QuickDraw

QPaintEngine.QWindowSystem

Qt for Embedded Linux

QPaintEngine.OpenGL

QPaintEngine.Picture

QPicture format

QPaintEngine.SVG

Scalable Vector Graphics XML format

QPaintEngine.Raster

QPaintEngine.Direct3D

Windows only, Direct3D based engine

QPaintEngine.Pdf

Portable Document Format

QPaintEngine.OpenVG

QPaintEngine.User

First user type ID

QPaintEngine.MaxUser

Last user type ID

QPaintEngine.OpenGL2

QPaintEngine.PaintBuffer

QPaintEngine.Blitter

QPaintEngine.Direct2D

Windows only, Direct2D based engine

PySide6.QtGui.QPaintEngine.state#
PySide6.QtGui.QPaintEngine.gccaps#
PySide6.QtGui.QPaintEngine.active#
PySide6.QtGui.QPaintEngine.selfDestruct#
PySide6.QtGui.QPaintEngine.extended#
abstract PySide6.QtGui.QPaintEngine.begin(pdev)#
Parameters:

pdevPySide6.QtGui.QPaintDevice

Return type:

bool

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. Return true if the initialization was successful; otherwise return false.

See also

end() isActive()

PySide6.QtGui.QPaintEngine.clearDirty(df)#
Parameters:

dfDirtyFlags

PySide6.QtGui.QPaintEngine.coordinateOffset()#
Return type:

PySide6.QtCore.QPoint

PySide6.QtGui.QPaintEngine.createPixmap(size)#
Parameters:

sizePySide6.QtCore.QSize

Return type:

PySide6.QtGui.QPixmap

PySide6.QtGui.QPaintEngine.createPixmapFromImage(image[, flags=Qt.AutoColor])#
Parameters:
Return type:

PySide6.QtGui.QPixmap

PySide6.QtGui.QPaintEngine.drawEllipse(r)#
Parameters:

rPySide6.QtCore.QRect

The default implementation of this function calls the floating point version of this function

PySide6.QtGui.QPaintEngine.drawEllipse(r)
Parameters:

rPySide6.QtCore.QRectF

Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.

The default implementation calls drawPolygon() .

PySide6.QtGui.QPaintEngine.drawImage(r, pm, sr[, flags=Qt.AutoColor])#
Parameters:

Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.

PySide6.QtGui.QPaintEngine.drawLines(lines, lineCount)#
Parameters:

This is an overloaded function.

The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function.

PySide6.QtGui.QPaintEngine.drawLines(lines, lineCount)
Parameters:

The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine.

PySide6.QtGui.QPaintEngine.drawPath(path)#
Parameters:

pathPySide6.QtGui.QPainterPath

The default implementation ignores the path and does nothing.

abstract PySide6.QtGui.QPaintEngine.drawPixmap(r, pm, sr)#
Parameters:

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.

PySide6.QtGui.QPaintEngine.drawPoints(points, pointCount)#
Parameters:

Draws the first pointCount points in the buffer points

The default implementation converts the first pointCount QPoints in points to QPointFs and calls the floating point version of drawPoints .

PySide6.QtGui.QPaintEngine.drawPoints(points, pointCount)
Parameters:

Draws the first pointCount points in the buffer points

PySide6.QtGui.QPaintEngine.drawPolygon(points, pointCount, mode)#
Parameters:

This is an overloaded function.

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

Note

At least one of the drawPolygon() functions must be reimplemented.

PySide6.QtGui.QPaintEngine.drawPolygon(points, pointCount, mode)
Parameters:

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

Note

At least one of the drawPolygon() functions must be reimplemented.

PySide6.QtGui.QPaintEngine.drawRects(rects, rectCount)#
Parameters:

This is an overloaded function.

The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function.

PySide6.QtGui.QPaintEngine.drawRects(rects, rectCount)
Parameters:

Draws the first rectCount rectangles in the buffer rects. The default implementation of this function calls drawPath() or drawPolygon() depending on the feature set of the paint engine.

PySide6.QtGui.QPaintEngine.drawTextItem(p, textItem)#
Parameters:

This function draws the text item textItem at position p. The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

PySide6.QtGui.QPaintEngine.drawTiledPixmap(r, pixmap, s)#
Parameters:

Reimplement this function to draw the pixmap in the given rect, starting at the given p. The pixmap will be drawn repeatedly until the rect is filled.

abstract PySide6.QtGui.QPaintEngine.end()#
Return type:

bool

Reimplement this function to finish painting on the current paint device. Return true if painting was finished successfully; otherwise return false.

See also

begin() isActive()

PySide6.QtGui.QPaintEngine.hasFeature(feature)#
Parameters:

featurePaintEngineFeatures

Return type:

bool

Returns true if the paint engine supports the specified feature; otherwise returns false.

PySide6.QtGui.QPaintEngine.isActive()#
Return type:

bool

Returns true if the paint engine is actively drawing; otherwise returns false.

See also

setActive()

PySide6.QtGui.QPaintEngine.isExtended()#
Return type:

bool

PySide6.QtGui.QPaintEngine.paintDevice()#
Return type:

PySide6.QtGui.QPaintDevice

Returns the device that this engine is painting on, if painting is active; otherwise returns None.

PySide6.QtGui.QPaintEngine.painter()#
Return type:

PySide6.QtGui.QPainter

Returns the paint engine’s painter.

PySide6.QtGui.QPaintEngine.setActive(newState)#
Parameters:

newState – bool

Sets the active state of the paint engine to state.

See also

isActive()

PySide6.QtGui.QPaintEngine.setDirty(df)#
Parameters:

dfDirtyFlags

PySide6.QtGui.QPaintEngine.setSystemClip(baseClip)#
Parameters:

baseClipPySide6.QtGui.QRegion

PySide6.QtGui.QPaintEngine.setSystemRect(rect)#
Parameters:

rectPySide6.QtCore.QRect

PySide6.QtGui.QPaintEngine.syncState()#
PySide6.QtGui.QPaintEngine.systemClip()#
Return type:

PySide6.QtGui.QRegion

PySide6.QtGui.QPaintEngine.systemRect()#
Return type:

PySide6.QtCore.QRect

PySide6.QtGui.QPaintEngine.testDirty(df)#
Parameters:

dfDirtyFlags

Return type:

bool

abstract PySide6.QtGui.QPaintEngine.type()#
Return type:

Type

Reimplement this function to return the paint engine Type .

abstract PySide6.QtGui.QPaintEngine.updateState(state)#
Parameters:

statePySide6.QtGui.QPaintEngineState

Reimplement this function to update the state of a paint engine.

When implemented, this function is responsible for checking the paint engine’s current state and update the properties that are changed. Use the state() function to find out which properties that must be updated, then use the corresponding get function to retrieve the current values for the given properties.