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

Animation in qml



  • Hi,

    I am unable to perform below mentioned scenario using qml:

    I want to show movement w.r.t "X" from left to right on click. Then again right to left onclicked.

    Can any one suggest some idea how to do this?



  • Hi @QtQmlLearner , can you share your code or your expected output so that, we can get to know more and suggest a better solution.

    Please have a look at the below code, it some simple stuff:-

     Rectangle {
            id: rect
    
            width: 100
            height: 100
            color: "red"
    
            SmoothedAnimation {
                id: anim
    
                duration: 1000
                target: rect
                property: "x"
            }
    
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    if(parent.x === 0) {
                        anim.to = 200;
                        anim.start();
                    } else {
                        anim.from = 200
                        anim.to = 0;
                        anim.start();
                    }
                }
            }
        }


  • @Shrinidhi-Upadhyaya
    Thank you so much. This is what i was expecting.


Log in to reply