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. Is this behavior of SpringAnimation normal?
Forum Update on Monday, May 27th 2025

Is this behavior of SpringAnimation normal?

Scheduled Pinned Locked Moved QML and Qt Quick
springanimation
1 Posts 1 Posters 417 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    Have a quick look at the code below. If you run it and spam the button, you will notice that it wont return to its desired position. This wont happen if you click it slowly and wait for the animation to finish.

    If instead of a SpringAnimation animation you use PropertyAnimation then the problem disappears.

    Is this normal, or a bug ?

    import QtQuick 2.2
    import QtGraphicalEffects 1.0
    
    Item {
        id: menuButton    
        state: "Closed"
    
        Rectangle {
            id: menuButtonIcon
            anchors.centerIn: parent
            //color: Qt.lighter("#C02A25", 1.25)
            color: "#D23F31"
            width: 65;
            height: 65;
            radius: width * 0.5
            antialiasing: true
            visible: false;
        }
    
        DropShadow {
            id: menuButtonIconShadow
            source: menuButtonIcon
            anchors.fill: source
            width: source.width
            height: source.height
            cached: true
            radius: 8.0
            samples: 16
            color: "#60000000"
            smooth: true
            horizontalOffset: 0.0
            verticalOffset: 0.0
            spread: 0.2
            transparentBorder: true
        }
    
        Rectangle {
            id: menuButtonIconBar1
            anchors.centerIn: menuButtonIcon
            width: 17
            height: 3
            antialiasing: true
        }
    
        Rectangle {
            id: menuButtonIconBar2
            anchors.centerIn: menuButtonIcon
            width: 17
            height: 3
            antialiasing: true
            rotation: 90
        }
    
        MouseArea {
            id: mouseArea
            anchors.fill: menuButtonIcon
            onPressed: menuButton.state = menuButton.state === "Open" ? "Closed" : "Open"
            //onClicked: menuButton.state = menuButton.state === "Open" ? "Closed" : "Open"
        }
    
        states: [
            State {
                name: "Closed"
            },
            State {
                name: "Open"
                PropertyChanges { target: menuButtonIconBar1; rotation: 135; scale: 0.92}
                PropertyChanges { target: menuButtonIconBar2; rotation: 225; scale: 0.92}
                PropertyChanges { target: menuButtonIconShadow; scale: 0.92}
            }
        ]
    
        transitions: [
            Transition {
                //RotationAnimation { target: menuButtonIconBar1; properties: "rotation"; duration: 400; easing.type: Easing.InOutQuad }
                //PropertyAnimation { target: menuButtonIconBar2; properties: "rotation"; duration: 400; easing.type: Easing.InOutQuad }
                //PropertyAnimation { target: menuButtonIconShadow; properties: "scale"; duration: 400; easing.type: Easing.InOutQuad }
                SpringAnimation { target: menuButtonIconShadow; properties: "scale"; spring: 3; damping: 0.25; epsilon: 0.2; mass: 1; modulus: 0; velocity: 0 }
                SpringAnimation { target: menuButtonIconBar1; properties: "rotation, scale"; spring: 3; damping: 0.25; epsilon: 0.5; mass: 1; modulus: 0; velocity: 0 }
                SpringAnimation { target: menuButtonIconBar2; properties: "rotation, scale"; spring: 3; damping: 0.25; epsilon: 0.5; mass: 1; modulus: 0; velocity: 0 }
            }
        ]
    }
    
    1 Reply Last reply
    0

    • Login

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