On this page

QCPainterWidget Class

QCPainterWidget is a widget for rendering using QCPainter. More...

Header: #include <QCPainterWidget>
Inherits: QRhiWidget

Public Functions

QCPainterWidget(QWidget *parent = nullptr)
virtual ~QCPainterWidget() override
QColor fillColor() const
bool hasSharedPainter() const
void setFillColor(const QColor &color)
void setSharedPainter(bool enable)

Protected Functions

virtual void graphicsResourcesInvalidated()
virtual void paint(QCPainter *painter)

Reimplemented Protected Functions

virtual void initialize(QRhiCommandBuffer *cb) override
virtual void releaseResources() override
virtual void render(QRhiCommandBuffer *cb) override

Detailed Description

Implement the paint virtual function in a subclass to perform rendering using a QCPainter.

Member Function Documentation

[explicit] QCPainterWidget::QCPainterWidget(QWidget *parent = nullptr)

Constructs a QCPainterWidget with the given parent.

[override virtual noexcept] QCPainterWidget::~QCPainterWidget()

Destroys the QCPainterWidget.

QColor QCPainterWidget::fillColor() const

Returns the current fill color.

See also setFillColor().

[virtual protected] void QCPainterWidget::graphicsResourcesInvalidated()

Called when underlying graphics resources, such as textures, are lost.

This indicates that QCImage objects returned from addImage() are no longer valid, and addImage() needs to be called again. If the paint() implementation is such that this does not matter, for example because images are not used, or addImage() is always called, then no action is necessary. Otherwise, it is recommended to toggle a flag, or similar, and act accordingly in the next invocation of paint().

The same applies to QCOffscreenCanvas objects returned from QCPainter::createCanvas(). When this function is called, the next invocation of paint() should create new canvases and redraw their contents.

See also QRhiWidget::releaseResources().

bool QCPainterWidget::hasSharedPainter() const

Returns true if this widget uses a shared painter.

See also setSharedPainter.

[virtual protected] void QCPainterWidget::paint(QCPainter *painter)

Reimplement this method to paint using painter.

This will get called after the item has been filled with fillColor().

[override virtual protected] void QCPainterWidget::releaseResources()

Reimplements: QRhiWidget::releaseResources().

void QCPainterWidget::setFillColor(const QColor &color)

Set the fill color to color. This color will be used to draw the background of the item. The default color is transparent.

See also fillColor().

void QCPainterWidget::setSharedPainter(bool enable)

Disable painter sharing if enable is false.

If painter sharing is enabled, all QCPainterWidget instances inside the same QWindow will use the same QCPainter. This function must be early, e.g. from the derived class' constructor, and must not be changed afterwards.

Painter sharing is enabled by default.

See also hasSharedPainter().

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.