Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Vector3d type as property in QML (2D)



  • Hi,

    Is it possible to use vector3d as property in an item ? It seems it don't works. Is it possible to register QVector3D to use it as property in items ?



  • Yes it works fine. You can use it in the axis property of a Rotation element and even animate that:

    @
    import QtQuick 1.0

    Item {
    width : 400
    height : 400
    Rectangle {
    x : 100
    y : 100
    width : 100
    height : 100
    color : "lightsteelblue"
    transform : Rotation {
    angle : 45
    // axis : Qt.vector3d(1, 0, 0)
    SequentialAnimation on axis {
    Vector3dAnimation {
    from : Qt.vector3d(0.3, 0.3, 0.3)
    to : Qt.vector3d(0, 0.6, 0.6)
    duration : 1000
    }
    Vector3dAnimation {
    from : Qt.vector3d(0, 0.6, 0.6)
    to : Qt.vector3d(0.3, 0.3, 0.3)
    duration : 1000
    }
    loops : Animation.Infinite
    }
    }
    }
    }
    @



  • I wants to have this for example :
    @
    Item{

    property vector3d value

    Text{
    text: value.x
    }

    }

    @



  • Hi,

    You can't directly declare properties of type vector3d, but you should be able to do something like this:

    @
    property variant value: Qt.vector3d(1,0,0)
    @

    Regards,
    Michael



  • ok so it's not possible to have a binded property in qml. There is no way to add new type as binded property ? Is it hardcoded in QML?



  • The types that can be used like:

    @property <type> <name>@

    in QML are currently hard-coded. You can see the list of supported types at http://doc.qt.nokia.com/4.7/qml-extending-types.html#supported-property-types.



  • thanks ... reading the documentation, I understand that I can use variant type ... so I can declare a variant property and use vector3 ?



  • Yes, you should be able to use a variant with vector3d as described earlier, i.e:

    @property variant value: Qt.vector3d(1,0,0)@

    Is that sufficient for your needs?



  • It seems that it works ... I have to check if it works with my C++ model for Qvector3D property binding


Log in to reply