Solved QtQuick 2 and paint()
-
Since QDeclarativeItem got deprecated, we have not been able to find a suitable replacement to use qml and paint() together. Our requirement involves painting custom items in a qml scene. We tried using QSG* but the documentation seems pretty confusing.
Also let us know how to use QGraphicsItem functions with QtQuick2. -
You can use QQuickPaintedItem https://doc.qt.io/qt-5/qquickpainteditem.html, it supports QPainter. Using QSG* classes is still a better option, though - for performance.
-
@sierdzio
We tried using QQuickPaintedItem and its paint function. We also called update whenever any change was made. But the paint function was not being invoked. If there is something that we are missing please tell.
Also the QQuickPaintedItem documentation quotes "This function, which is usually called by the QML Scene Graph, paints the contents of an item in local coordinates.". I am guessing this means a scene graph is required for using the paint() method. -
@Luckless said in QtQuick 2 and paint():
@sierdzio
We tried using QQuickPaintedItem and its paint function. We also called update whenever any change was made. But the paint function was not being invoked. If there is something that we are missing please tell.Make sure you set ItemHasContents flag https://doc.qt.io/qt-5/qquickitem.html#Flag-enum
Also the QQuickPaintedItem documentation quotes "This function, which is usually called by the QML Scene Graph, paints the contents of an item in local coordinates.". I am guessing this means a scene graph is required for using the paint() method.
Yes Scene Graph is needed but you don't need to use it. You just pain using QPainter and QML engine does the rest.
Your application uses QML, right? And this item is part of some QML scene? Or you are using it in some less conventional environment?