Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to make the animation run as expected
Qt 6.11 is out! See what's new in the release blog

How to make the animation run as expected

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 363 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deepak05
    wrote on last edited by deepak05
    #1

    Here I want the heading to go in 45* angle from on place to another, but while coming back it is going to the top and then coming to the required place. This is the code:
    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 1.6

    Window {
    id: root
    visible: true
    title: qsTr("Hello World")
    property bool fullScreen: true
    height: 7804
    width: 640

    Item
    {
        id:screen
        state: fullScreen?"landscape":"landscape-small"
        height: parent.height
        states: [
            State {
                name: "landscape"
                PropertyChanges {
                    target: screen
                    width:parent.width
                }
                AnchorChanges
                {
                    target: screen
    

    // anchors.fill: parent
    anchors.left: root.left
    }

                PropertyChanges {
                    target: rect
                    width:200
                    height:200
                }
                AnchorChanges {
                    target: name
                    anchors.top: screen.top
                    anchors.horizontalCenter: screen.horizontalCenter
                }
                PropertyChanges {
                    target: name
                    anchors.topMargin: 150
                }
                PropertyChanges {
                    target: root
                    width: 640
                }
            },
            State {
                name: "landscape-small"
                PropertyChanges {
                    target: screen
                    width: 200
                     anchors.right: parent.right
    
                }
    
                PropertyChanges {
                    target: rect
                    width:100
                    height:100
                }
                AnchorChanges {
                    target: name
                    anchors.top: rect.bottom
                                    anchors.horizontalCenter: screen.horizontalCenter
    
                }
                PropertyChanges {
                    target: name
                    anchors.topMargin: 20
                }
                PropertyChanges {
                    target: root
                    width: 300
    
                }
            }
        ]
        transitions: [
            Transition {
                from: "landscape"
                to: "landscape-small"
                ParallelAnimation
                {
                    NumberAnimation
                    {
                        target: root
                        property: "scale"
                        duration: 304
                        easing.type: Easing.Linear
    

    // easing.bezierCurve: [0.5,0,0,1]
    }
    // PauseAnimation { duration: 100 }
    ParallelAnimation
    {
    NumberAnimation
    {
    target: screen
    duration: 304
    easing.type: Easing.Linear
    // easing.bezierCurve: [0.5,0.5,0,1]
    property: "width"
    }

                        NumberAnimation
                        {
                            target: name
                            //                    properties: "x,y"
                            duration: 304
                            easing.type: Easing.Linear
                            easing.bezierCurve: [0.5,0.5,0,1]
                            //                    to: rect.bottom
                            //                    from: screen.top
                        }
                        NumberAnimation
                        {
                            target: rect
                            property: "scale"
                            duration: 304
                            easing.type: Easing.Linear
                            easing.bezierCurve: [0.5,0,0,1]
                        }
    
                        AnchorAnimation
                        {
                            duration: 304
                            easing.type: Easing.Linear
                            easing.bezierCurve: [0.5,0.5,0,1]
                        }
                    }
                }
            },
            Transition {
                from: "landscape-small"
                to: "landscape"
    

    // ParallelAnimation
    // {

                    //                PauseAnimation { duration: 100 }
                    ParallelAnimation
                    {
                        NumberAnimation
                        {
                            target: root
    

    // property: "scale"
    properties: "x,y"
    duration: 30
    easing.type: Easing.Linear
    easing.bezierCurve: [0.5,0,0,1]
    }
    AnchorAnimation
    {
    duration: 304
    easing.type: Easing.Linear
    easing.bezierCurve: [0.5,0,0,1]
    }

                        NumberAnimation
                        {
                            target: screen
                            duration: 304
                            property: "width"
                            easing.type: Easing.Linear
                            easing.bezierCurve: [0.5,0.5,0,1]
                        }
    

    // NumberAnimation
    // {
    // target: name
    //// properties: "x,y"
    // duration: 608
    // easing.type: Easing.Linear
    // easing.bezierCurve: [0.5,0,0,1]
    // // to: screen.top
    // // from: rect.bottom
    // }
    // NumberAnimation {
    // target: name
    // property: "x"
    // to: screen.width / 2 - name.width / 2
    // duration: 608
    // easing.type: Easing.Linear
    // }
    // NumberAnimation {
    // target: name
    //// property: "y"
    //// to: 150 // same as anchors.topMargin in "landscape"
    // duration: 608
    // easing.type: Easing.Linear
    // }
    PathAnimation
    {
    target: name

                        }
    
                        NumberAnimation
                        {
                            target: rect
                            property: "scale"
                            duration: 304
                            easing.type: Easing.Linear
                            easing.bezierCurve: [0.5,0,0,1]
                        }
    
    
                    }
    

    // NumberAnimation
    // {
    // target: root
    // property: "scale"
    // duration: 304
    // easing.type: Easing.Linear
    //// easing.bezierCurve: [0.5,0,0,1]
    // }
    // }
    }
    ]
    Rectangle
    {
    id: rect
    width: 200
    height: 200
    color:"red"
    anchors.right: parent.right
    anchors.rightMargin: 40
    anchors.verticalCenter: parent.verticalCenter
    MouseArea
    {
    anchors.fill: parent
    onClicked: fullScreen=!fullScreen
    }
    }
    Text {
    id: name
    anchors.horizontalCenter: screen.horizontalCenter
    text: qsTr("Highway to Hell")

            //        anchors.verticalCenter: parent.verticalCenter
        }
    }
    

    }

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      Please learn to format your code correctly. It makes things so much easier for those attempting to help you.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved