PySide6.QtCanvasPainter.QCanvasPainterItem¶
- class QCanvasPainterItem¶
The
QCanvasPainterItemclass 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
QCanvasPainterItemsubclass. SeeQCanvasPainterItemRendererfor an example of theMyRendererclass.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
See also
Synopsis¶
Properties¶
fillColorᅟ- Color to use for filling the item ie. the item background
Methods¶
def
__init__()def
debug()def
fillColor()def
setFillColor()
Virtual methods¶
Signals¶
def
debugChanged()
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_propertyis 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_COLLECTis 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_RENDERinstead. 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:
Signal
debugChanged()
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:
parent –
QQuickItem
Constructs a
QCanvasPainterItemwith the givenparentitem.- abstract createItemRenderer()¶
- Return type:
Implement this method to (re)create a painter for this item. The painter class should be inherited from
QCanvasPainterItemRenderer.QCanvasPainterItemtakes 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ᅟ.Returns the current fill color.
See also
Getter of property
fillColorᅟ.- fillColorChanged()¶
Notification signal of property
fillColorᅟ.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()alphaBlendingSetter of property
fillColorᅟ.