PySide6.QtCanvasPainter.QCanvasPainterItem

class QCanvasPainterItem

The QCanvasPainterItem class provides a way to use the Qt Canvas Painter API in the QML Scene Graph.

Details

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

To write your own painted item, you first create a subclass of QCanvasPainterItem , and then start by implementing its only pure virtual public function: createItemRenderer() , which returns an object that performs the actual painting.

The below code snippet shows the typical structure of a QCanvasPainterItem subclass. See QCanvasPainterItemRenderer for an example of the MyRenderer class.

class MyItem(QCanvasPainterItem):

    Q_OBJECT
    QML_NAMED_ELEMENT(MyItem) // exposed to QML, instantiate as MyItem { ... }
    # a custom property
    Q_PROPERTY(float value READ value WRITE setValue NOTIFY valueChanged)
# public
    HelloItem(QQuickItem parent = None)
    super().__init__(parent)


    QCanvasPainterItemRenderer createItemRenderer() override

        return MyRenderer()

    float value() { return m_value; }
    def setValue(newValue):

        if m_value != newValue:
            m_value = newValue
            valueChanged.emit()


    m_value = 0.0f

Inheritance diagram of PySide6.QtCanvasPainter.QCanvasPainterItem

Synopsis

Properties

Methods

Virtual methods

Signals

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

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property debugᅟ: Dictionary with keys of type .QString and values of type QVariant.

Contains a key - value map of rendering statistics. The data is only collected when the environment variable QCPAINTER_DEBUG_COLLECT is set to a non-zero value.

The data is updated periodically, not every time the item repaints. The interval is currently one second. Therefore, the data received will in many cases refer to a previous drawing of the item. This is not usually an issue when displaying the statistics interactively, but it is important to be aware of.

To automatically show the data within the item in form of an overlay, set the environment variable QCPAINTER_DEBUG_RENDER instead. This provides a convenient shortcut when the intention is anyway to show the values on-screen.

The list of keys is currently the following:

  • fillDrawCallCount

  • strokeDrawCallCount

  • textDrawCallCount

  • fillTriangleCount

  • strokeTriangleCount

  • textTriangleCount

  • drawCallCount

  • triangleCount

Access functions:
property fillColorᅟ: QColor

This property holds The color to use for filling the item ie. the item background..

The default color is black.

Access functions:
__init__([parent=None])
Parameters:

parentQQuickItem

Constructs a QCanvasPainterItem with the given parent item.

abstract createItemRenderer()
Return type:

QCanvasPainterItemRenderer

Implement this method to (re)create a painter for this item. The painter class should be inherited from QCanvasPainterItemRenderer . QCanvasPainterItem takes the ownership of the created object and deletes it when needed.

Example code:

QCanvasPainterItemRenderer * MyItem::createItemRenderer() const { return new MyItemPainter(); }

debug()
Return type:

Dictionary with keys of type .QString and values of type QVariant.

Getter of property debugᅟ .

debugChanged()

Notification signal of property debugᅟ .

fillColor()
Return type:

QColor

Returns the current fill color.

See also

setFillColor()

Getter of property fillColorᅟ .

fillColorChanged()

Notification signal of property fillColorᅟ .

setFillColor(color)
Parameters:

colorQColor

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

Note

When setting the fill color to not fully opaque (alpha channel less than 255), remember to set also alphaBlending to true.

See also

fillColor() alphaBlending

Setter of property fillColorᅟ .