How to get position of QML Items in C++?
-
I would like to know what the x, y and width, height of each QML Item is, from C++. Would I need to inspect the QQuickItems or somehow introspect the render nodes? Is there an example or more info on how I can do this?
Background: We are rendering offscreen / headless. When we switched away from software rendered QWidget/QPainter to QtQuick 2 we lost the information about dirty regions. We need to get this back somehow, as we need this information later.
-
I would like to know what the x, y and width, height of each QML Item is, from C++. Would I need to inspect the QQuickItems or somehow introspect the render nodes? Is there an example or more info on how I can do this?
Background: We are rendering offscreen / headless. When we switched away from software rendered QWidget/QPainter to QtQuick 2 we lost the information about dirty regions. We need to get this back somehow, as we need this information later.
hi @likewise
the easiest solution is probably to give your qml object an objectName and using findChild to search for the QObject.
https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#accessing-loaded-qml-objects-by-object-nameand than simply read the property e.g:
int x = myObject->property("x").toInt();