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. Animation.onFinished not firing
Forum Updated to NodeBB v4.3 + New Features

Animation.onFinished not firing

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 991 Views 3 Watching
  • 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.
  • LorenDBL Offline
    LorenDBL Offline
    LorenDB
    wrote on last edited by
    #1

    I've got a project in which I am fooling around with various animations and transitions for the fun of it. However, I am not happy to find that Animation.onFinished is not firing as I would think it should. My code is in two files: main.qml:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        id: windowRoot
    
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        function showMainPage() {
            loader.sourceComponent = mainPage
        }
    
        Loader {
            id: loader
    
            anchors.fill: parent
            sourceComponent: loadingPage
        }
    
        Component {
            id: mainPage
    
            Rectangle {
                color: "lightsteelblue"
            }
        }
    
        Component {
            id: loadingPage
    
            Rectangle {
                anchors.fill: parent
    
                LoadingPage {
                    anchors.centerIn: parent
                }
            }
        }
    }
    

    ...and LoadingPage.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    ProgressBar {
        id: pb
    
        states: State {
            name: "go"
    
            PropertyChanges {
                target: pb
                value: pb.to
            }
        }
    
        transitions: [
            Transition {
                reversible: true
    
                SequentialAnimation {
                    PauseAnimation {
                        duration: 500
                    }
    
                    NumberAnimation {
                        target: pb
                        properties: "value"
                        duration: 1000
                        easing.type: Easing.InOutQuad
                        alwaysRunToEnd: true
                    }
    
                    PauseAnimation {
                        duration: 500
                        onFinished: windowRoot.showMainPage()
                    }
                }
            }
        ]
    
        Label {
            text: qsTr("Loading...")
            anchors.bottom: pb.top
            anchors.horizontalCenter: pb.horizontalCenter
            anchors.margins: 5
        }
    
        Component.onCompleted: pb.state = "go"
    }
    

    For some reason, the second PauseAnimation does not actually fire the onFinished signal. I've also tried with onFinished as part of the NumberAnimation, with the same results.

    I'm using Qt 5.12.8 from the Ubuntu 20.04 repos, and I've also tried 5.15.1 and 6.0.0 without any success.

    1 Reply Last reply
    0
    • SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by
      #2

      You might to try

      ScriptAction {
        script: doSomething()
      }
      

      after that PauseAnimation

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        https://doc.qt.io/qt-6/qml-qtquick-animation.html#finished-signal says:

        In addition, it is only emitted for top-level, standalone animations. It will not be emitted for animations in a Behavior or Transition, or animations that are part of an animation group.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        LorenDBL 1 Reply Last reply
        0
        • jeremy_kJ jeremy_k

          https://doc.qt.io/qt-6/qml-qtquick-animation.html#finished-signal says:

          In addition, it is only emitted for top-level, standalone animations. It will not be emitted for animations in a Behavior or Transition, or animations that are part of an animation group.

          LorenDBL Offline
          LorenDBL Offline
          LorenDB
          wrote on last edited by
          #4

          @SeeLook thanks, that did the trick.

          @jeremy_k oops, not sure why I didn't see that.

          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