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. PropertyAnimation in signal handler
Qt 6.11 is out! See what's new in the release blog

PropertyAnimation in signal handler

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 566 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
    Mark81
    wrote on last edited by Mark81
    #1

    According to the docs the PropertyAnimation can be used in signal handlers:

    MouseArea {
        anchors.fill: theObject
        onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
    }
    

    But why is not possible to use the braces around?

    MouseArea {
        anchors.fill: theObject
        onClicked: {
            PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
        }
    }
    

    This leads to the following error:

    Expected token ,

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Because when using braces you are now in a javascript scope, and you can't create QML objects declaratively like that in js.

      What are you trying to do?

      My 2 cents: I wasn't even aware that you could do that and my first reaction was disbelief. This QML feature of assigning an animation to a signal handler seems like a bad idea and isn't really intuitive.

      M 1 Reply Last reply
      0
      • GrecKoG GrecKo

        Because when using braces you are now in a javascript scope, and you can't create QML objects declaratively like that in js.

        What are you trying to do?

        My 2 cents: I wasn't even aware that you could do that and my first reaction was disbelief. This QML feature of assigning an animation to a signal handler seems like a bad idea and isn't really intuitive.

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @GrecKo I was trying to find a way to execute an animation without declaring it separately. In "meta-code":

        onSignalTrigger: {
            timer.stop()
            doSomething()
            doSomethingElse()
            // animate property
            PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
        }
        

        The long way is:

        PropertyAnimation { id: myAnim; target: theObject; property: "opacity"; to: 0 }
        
        onSignalTrigger: {
            timer.stop()
            doSomething()
            doSomethingElse()
            // animate property
            myAnim.start()
        }
        

        I find the first syntax is more readable

        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