PySide6.QtCanvasPainter.QCanvasPainterFactory

class QCanvasPainterFactory

QCanvasPainterFactory manages instances of QCanvasPainter and the associated rendering engine.

Details

Applications rendering via QCanvasPainter do not create instances of the painter class themselves, but rather are expected to use a QCanvasPainterFactory .

Note

This class is relevant only when working with QCanvasPainter without a convenience class such as QCanvasPainterWidget or QCanvasPainterItem , because those provide a QCanvasPainter instance to the application.

The following is an example code snippet of getting a QCanvasPainter for use with an existing, successfully initialized QRhi:

std::unique_ptr<QCanvasPainterFactory> factory(new QCanvasPainterFactory);
QCanvasPainter *painter = factory->create(rhi);
QCanvasRhiPaintDriver *paintDriver = factory->paintDriver();

All drawing code that operates on the same thread with the same QRhi is recommended to share and reuse the same QCanvasPainter , instead of having a dedicated painter (and so factory) in each component. This can be achieved by calling sharedInstance() , instead of constructing a new QCanvasPainterFactory :

QCanvasPainterFactory *factory = QCanvasPainterFactory::sharedInstance(rhi);
QCanvasPainter *painter = factory->painter();
QCanvasRhiPaintDriver *paintDriver = factory->paintDriver();

Synopsis

Methods

Static 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

__init__()

Constructor.

See also

sharedInstance()

create(rhi)
Parameters:

rhiQRhi

Return type:

QCanvasPainter

Initializes the QCanvasPainter rendering infrastructure, if it has not been done already for this factory.

Returns the painter, or null if the renderer could not be initialized.

The factory will be associated with rhi, and it cannot be used with any other QRhi, unless destroy() , and then create() are called again.

Repeated calls to this function have no effect and are harmless. Call destroy() first if a reinitialization of the painter infrastructure is desired, possibly with a different rhi.

Note

There is no need to call this function when sharedInstance() was used to retrieve a factory instance.

destroy()

Tears down the rendering infrastructure. Normally there is no need to call this function. Rather, it is used in situations where it will be followed by a create() .

See also

create()

isValid()
Return type:

bool

Returns true if the create() has ben called successfully.

paintDriver()
Return type:

QCanvasRhiPaintDriver

Returns the paint driver object, or null if isValid() is false.

Note

The returned object is not owned by the caller.

painter()
Return type:

QCanvasPainter

Returns the painter, or null if isValid() is false.

Note

The returned object is not owned by the caller.

static sharedInstance(rhi)
Parameters:

rhiQRhi

Return type:

QCanvasPainterFactory

Returns a QCanvasPainterFactory instance associated with the given rhi.

Calling this function with the same rhi will always return the same QCanvasPainterFactory .

There is no need to call create() on the returned factory, and the painter() can be queried right away, because the result is always already initialized, meaning isValid() returns true.

This function is thread safe. However, the QRhi threading rules apply as usual: a QRhi object, and by extension, an instance of QCanvasPainterFactory , QCanvasRhiPaintDriver , and QCanvasPainter associated with that QRhi are all expected to be used on the same one single thread.

Note

The returned QCanvasPainterFactory is not owned by the caller, and it becomes invalid when rhi is destroyed.

See also

painter()