[Interest] Qt3D/QML How to access a QTransform based property from C++
Sean Harmer
sean.harmer at kdab.com
Wed Aug 30 11:37:28 CEST 2017
Set the properties on the QTransform, not the QTransform itself. But in
general don't poke up into the QML layer from C++. Much better idea to bind
the transform in QML to properties on an object you export from C++ to QML.
i.e.
Entity {
components: [
Transform {
translation: _myObject.position
}
]
}
then from C++:
class MyObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QVector3D position ...)
...
}
auto myObject = new MyObject();
rootContext()->setContextProperty("_myObject", myObject);
Then just update the properties on your myObject and the QML will reflect this.
With this approach, if you change your QML, your lower C++ layer won't break.
Cheers,
Sean
On Wednesday, 30 August 2017 09:07:08 BST Volker Enderlein wrote:
> Hi all,
>
> for an animation system I try to construct some parameterized QML
> components that provide access to their transformation and material via
> properties. The QML part looks the following way:
>
> import Qt3D.Core 2.0
> import Qt3D.Render 2.0
> import QtQuick 2.0
> import Qt3D.Extras 2.0
>
> Entity {
> id: root
>
> property Transform frame: Transform {}
> property Material mat: PhongMaterial { diffuse: Qt.rgba(0.8, 0.8,
> 0.8, 1.0) }
> ...
>
> }
>
> Later I try to update the Transform and Material from C++. But I cannot
> set the properties via qmlEntity->setProperty("Transform",
> QVariant(Qt3DCore::QTransform)); because QTransform is not usable as
> metatype.
>
> How would I do that, or should I use an entirely different approach?
>
>
> Cheers Volker
--
--
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. UK +44 (0)1625 809908, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
More information about the Interest
mailing list