Accessing properties of 2D QML object in a 3DView via C++
-
How can I access the properties of a 2D object that is in a 3D view?
example.qml:
View3D { Node { objectName: "myNodeObj", x: 10 Text { objectName: "myTextObj", text: "Some text" } }
I can access the properties of Node with:
QObject *n = ui.quickWidget->rootObject()->findChild<QObject*>("myNodeObj"); n->setProperty("x", 3);
However, this doesn't work for 2D objects such as Text:
QObject *t = ui.quickWidget->rootObject()->findChild<QObject*>("myTextObj");
Returns nullptr, so I can't change the text.
If I print out the children of Node, then rather than finding a Text object, it's been replaced with an unnamed private QQuick3DItem2D. https://doc.qt.io/qt-6/qtquick3d-architecture.html says that 2D items get wrapped in QQuick3DItem2Ds. How can they be accessed?
Thanks.