QCanvasOffscreenCanvas Class

QCanvasOffscreenCanvas represents an offscreen canvas that QCanvasPainter can target. More...

Header: #include <QCanvasOffscreenCanvas>
CMake: find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)
Since: Qt 6.11
Status: Technical Preview

Detailed Description

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 QCanvasPainter::createCanvas(). To target an offscreen canvas with with draw commands, call the appropriate QCanvasRhiPaintDriver::beginPaint() overload when working with the lower level API, or QCanvasPainterWidget::beginCanvasPainting() or QCanvasPainterItemRenderer::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.