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. Listview Populate Transition Interrupted
QtWS25 Last Chance

Listview Populate Transition Interrupted

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 153 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.
  • A Offline
    A Offline
    afalsa
    wrote on 8 Apr 2025, 21:31 last edited by afalsa 4 Aug 2025, 21:32
    #1

    Hello!

    Problem
    With the code shown at the bottom of this message, the following issue occurs: if the populate animation is running and, at the same time, the hover animation of the delegate is triggered, the delegate ends up with an unexpected scale.

    So, is there any way to avoid this?

    I know I can control the state of the corresponding MouseArea in the delegate, but I was hoping to find a less hacky solution.

    Thank you!

    54f93bdd-69e1-4739-baea-186af10744b8-image.png


    Some links I have visited

    https://doc.qt.io/qt-6.8/qml-qtquick-viewtransition.html#handling-interrupted-animations
    https://doc.qt.io/qt-6/qml-qtquick-transition.html


    Code (Copy & Paste to try)

    import QtQuick
    import QtQuick.Controls
    
    Item {
        id: root
        width: 1920
        height: 1080
    
        ListView {
            id: repeaterModel
            anchors.fill: parent
    
            spacing: 10
    
            model: 5
    
            orientation: ListView.Horizontal
    
            delegate: Rectangle {
                id: test_delegate
                anchors.verticalCenter: parent.verticalCenter
                width: 100
                height: 200
                color: "red"
    
                property real normalScale: 1.0
                property real zoomedScale: 1.2
                property real normalRotation: 0
                property real zoomedRotation: 0
    
                onScaleChanged: console.log("Scale changed %1".arg(scale))
    
                MouseArea {
                    id: mouseArea
                    anchors.fill: parent
                    hoverEnabled: true
                    onEntered: test_delegate.state = "zoomed"
                    onExited: test_delegate.state = ""
                }
    
                states: [
                    State {
                        name: "zoomed"
                        PropertyChanges {
                            target: test_delegate
                            scale: zoomedScale
                            rotation: zoomedRotation
                        }
                    }
                ]
    
                transitions: [
                    Transition {
                        from: ""
                        to: "zoomed"
                        ParallelAnimation {
                            NumberAnimation {
                                properties: "scale"
                                duration: 300
                                easing.type: Easing.OutBack
                            }
                            NumberAnimation {
                                properties: "rotation"
                                duration: 300
                                easing.type: Easing.OutBack
                            }
                        }
                    },
                    Transition {
                        from: "zoomed"
                        to: ""
                        ParallelAnimation {
                            NumberAnimation {
                                properties: "scale"
                                duration: 300
                                easing.type: Easing.InBack
                            }
                            NumberAnimation {
                                properties: "rotation"
                                duration: 300
                                easing.type: Easing.InBack
                            }
                        }
                    }
                ]
            }
    
            populate: Transition {
                id: transition
                SequentialAnimation {
    
                    ScriptAction {
                        script: {
                            console.log(transition.ViewTransition.index) /* prints as intended */
                        }
                    }
                    PropertyAction {
                        property: "scale"
                        value: 0
                    }
                    PauseAnimation {
                        duration: transition.ViewTransition.index * 100
                    }
                    NumberAnimation {
                        duration: 500
                        properties: "scale"
                        from: 0
                        to: 1
                    }
                }
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      afalsa
      wrote 28 days ago last edited by
      #2

      Hello again!

      After some digging, I’ve found an "elegant" solution.

      First, setting the NumberAnimation with a duration of 500 (population animation) was interfering with the hover animation duration (Delegate), which is 300. That was causing some weird behavior.

      The second part is that I added the property change in the "" state, which fixed the issue and now the element returns to its original position even if the animation gets interrupted.

                  states: [
                      State {
                          name: "zoomed"
                          PropertyChanges {
                              target: test_delegate
                              scale: zoomedScale
                              rotation: zoomedRotation
                          }
                      },
                      State {
                          name: ""
                          PropertyChanges {
                              target: test_delegate
                              scale: normalScale
                              rotation: normalRotation
                          }
                      }
                  ]
      
      1 Reply Last reply
      0
      • A afalsa has marked this topic as solved 28 days ago

      1/2

      8 Apr 2025, 21:31

      • Login

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