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 there a way to tell if an Item is running a State Transition?
Qt 6.11 is out! See what's new in the release blog

Is there a way to tell if an Item is running a State Transition?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.0k Views 1 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.
  • M Offline
    M Offline
    mbarclaygmail.com
    wrote on last edited by
    #1

    I don't understand why this doesn't work. When clicking, I expected the text to change to "Running: true". I want to know when an Item is in transition so I can chain together multiple states. i.e. go to state1, <signal>, go to state2.

    qmlviewer -sizeviewtorootobject trans.qml
    @
    import Qt 4.7

    Rectangle {
    id: root
    property bool inTransition: trans1.running

    width: 640
    height: 480
    
    Text {
        anchors.centerIn: parent
        font.pixelSize: 32
        text: "Running: " + inTransition
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            if(root.state == "big") {
                root.state = ""
            } else {
                root.state = "big"
            }
        }
    }
    
    states: [
        State {
            name: "big"
            PropertyChanges {
                target: root
                width: 800
                height: 600
            }
        }
    ]
    
    transitions: [
        Transition {
            id: trans1
            property bool running: anim1.running || anim2.running
    
            PropertyAnimation { id: anim1; properties: "width";  duration: 2000 }
            PropertyAnimation { id: anim2; properties: "height"; duration: 3000 }
        }
    ]
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      It isn't currently possible to tell when an animation in a transition is running, see http://bugreports.qt.nokia.com/browse/QTBUG-13927.

      For a simple example like the above, you could add a ScriptAction to the end of the transition that would fire a signal or set the new state. There is also an (undocumented, so I'm unsure whether its officially supported) onCompleted signal handler in the State element, that fires once the transition is complete, and the state is fully entered.

      Regards,
      Michael

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbarclaygmail.com
        wrote on last edited by
        #3

        Hi Michael,

        Thanks for the suggestion! Here's a working example based on the information you provided. I'm trying to create a new Item called SmartTransition to encapsulate the ScriptAction and property setting. I'll post it if I figure something out.

        @
        import Qt 4.7

        Rectangle {
        id: root
        property bool inTransition: trans1.inTransition
        width: 640
        height: 480

        Text {
            anchors.centerIn: parent
            font.pixelSize: 32
            text: "Running: " + inTransition
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                if(root.state == "big") {
                    root.state = ""
                } else {
                    root.state = "big"
                }
            }
        }
        states: [
            State {
                name: "big"
                PropertyChanges {
                    target: root
                    width: 800
                    height: 600
                }
            }
        ]
        transitions: [
            Transition {
                id: trans1
                property bool inTransition: false
                SequentialAnimation {
                    ScriptAction { script: { inTransition = true } }
                    ParallelAnimation {
                        PropertyAnimation { properties: "width";  duration: 2000 }
                        PropertyAnimation { properties: "height"; duration: 3000 }
                    }
                    ScriptAction { script: { inTransition = false } }
                }
        
            }
        ]
        

        }
        @

        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