PySide6.QtCanvasPainter.QCanvasPainterFactory¶
- class QCanvasPainterFactory¶
QCanvasPainterFactorymanages instances ofQCanvasPainterand the associated rendering engine.Details
Applications rendering via
QCanvasPainterdo not create instances of the painter class themselves, but rather are expected to use aQCanvasPainterFactory.Note
This class is relevant only when working with
QCanvasPainterwithout a convenience class such asQCanvasPainterWidgetorQCanvasPainterItem, because those provide aQCanvasPainterinstance to the application.The following is an example code snippet of getting a
QCanvasPainterfor 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 callingsharedInstance(), instead of constructing a newQCanvasPainterFactory:QCanvasPainterFactory *factory = QCanvasPainterFactory::sharedInstance(rhi); QCanvasPainter *painter = factory->painter(); QCanvasRhiPaintDriver *paintDriver = factory->paintDriver();
Synopsis¶
Methods¶
def
__init__()def
create()def
destroy()def
isValid()def
paintDriver()def
painter()
Static functions¶
def
sharedInstance()
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
Initializes the
QCanvasPainterrendering 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, unlessdestroy(), 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 differentrhi.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
- isValid()¶
- Return type:
bool
Returns true if the
create()has ben called successfully.- paintDriver()¶
- Return type:
Returns the paint driver object, or null if
isValid()is false.Note
The returned object is not owned by the caller.
- painter()¶
- Return type:
Returns the painter, or null if
isValid()is false.Note
The returned object is not owned by the caller.
- Parameters:
rhi –
QRhi- Return type:
Returns a
QCanvasPainterFactoryinstance associated with the givenrhi.Calling this function with the same
rhiwill always return the sameQCanvasPainterFactory.There is no need to call
create()on the returned factory, and thepainter()can be queried right away, because the result is always already initialized, meaningisValid()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, andQCanvasPainterassociated with that QRhi are all expected to be used on the same one single thread.Note
The returned
QCanvasPainterFactoryis not owned by the caller, and it becomes invalid whenrhiis destroyed.See also