PySide6.QtCanvasPainter.QCanvasOffscreenCanvas

class QCanvasOffscreenCanvas

QCanvasOffscreenCanvas represents an offscreen canvas that QCanvasPainter can target.

Details

An offscreen canvas is essentially a color buffer (a QRhiTexture), and possibly other associated graphics resources. After content has been rendered into the canvas’s color buffer, the canvas can be registered to the painter to retrieve a QCanvasImage that can then be used in drawImage() calls or as an image pattern .

To create an offscreen canvas, call createCanvas() . To target an offscreen canvas with with draw commands, call the appropriate beginPaint() overload when working with the lower level API, or beginCanvasPainting() or beginCanvasPainting() when using the convenience widget or Qt Quick item classes.

Similarly to QCanvasImage and QCanvasBrush , QCanvasOffscreenCanvas is explicitly shared. See Implicit Data Sharing and QSharedDataPointer for details.

Note

As with QCanvasImage , a QCanvasOffscreenCanvas can be seen as an object merely containing handles. Even when a detach occurs, the actual resources, e.g. the underlying texture and the image data in it, are never actually copied or duplicated. The actual owner of any real graphics resources (e.g., a QRhiTexture) is the QCanvasPainter that handed out the QCanvasOffscreenCanvas via createCanvas() .

A canvas always belongs to the QCanvasPainter that created it. Manually destroying canvases is done by calling destroyCanvas() . In most cases this will not be necessary, however, since the painter will automatically destroy any canvases during its own destruction.

Synopsis

Methods

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

class Flag

(inherits enum.Flag) Specifies the flags for the canvas.

Constant

Description

QCanvasOffscreenCanvas.Flag.Flag.PreserveContents

Indicates that the contents of the canvas is preserved when painting to it. This can have a negative effect on performance, depending on the GPU architecture. See QRhiTextureRenderTarget::PreserveColorContents for details. Setting this flag is not supported when the sample count is greater than 1.

QCanvasOffscreenCanvas.Flag.Flag.MipMaps

Indicates that the canvas’ backing texture should have mipmapping enabled. Setting this flag is not supported when the sample count is greater than 1. Note that the mipmap sequence is generated when calling addImage() with the GenerateMipmaps flag set. This implies that addImage() must be called every time after the canvas’ content changes, so that the mipmap chain is regenerated. Frequent mipmap generation can have a negative effect on performance.

__init__()
__init__(canvas)
Parameters:

canvasQCanvasOffscreenCanvas

Copy constructor.

fillColor()
Return type:

QColor

Returns the current fill color.

See also

setFillColor()

flags()
Return type:

Combination of Flag

Returns the flags with which the canvas was created.

The flags are immutable and cannot be changed once the canvas has been created.

isNull()
Return type:

bool

Returns true if this canvas has valid data.

Normally this will always be true.

See also

texture()

__ne__(rhs)
Parameters:

rhsQCanvasOffscreenCanvas

Return type:

bool

__eq__(rhs)
Parameters:

rhsQCanvasOffscreenCanvas

Return type:

bool

setFillColor(color)
Parameters:

colorQColor

Sets the fill (clear) color to color.

By default this is set to the value passed to createCanvas() .

See also

fillColor()

swap(other)
Parameters:

otherQCanvasOffscreenCanvas

texture()
Return type:

QRhiTexture

Returns the texture backing this offscreen canvas.

See also

isNull()