Important: Please read the Qt Code of Conduct -

Dynamic attached Behavior

  • Qt Champions 2016


    Is it possible to attach a Behavior object to a QML item dynamically?

    For example, take out the "Behavior on width" from the code, and assign another "Behavior" after construction by code?

    import QtQuick 2.0
    Rectangle {
        id: rect
        width: 100; height: 100
        color: "red"
        Behavior on width {
            NumberAnimation { duration: 1000 }
        MouseArea {
            anchors.fill: parent
            onClicked: rect.width = 50

Log in to reply