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. Code redundancy when creating Transition
QtWS25 Last Chance

Code redundancy when creating Transition

Scheduled Pinned Locked Moved Solved QML and Qt Quick
animationtransition
3 Posts 3 Posters 941 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.
  • Stefan Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on last edited by Stefan Monov76
    #1

    My code:

    states: [
        State {
            name: "pressed"; when: mouseArea.pressed
            PropertyChanges {
                target: foo
                prop1: 10
                prop2: 10
                prop3: 10
            }
        },
        State {
            name: "notPressed"; when: !mouseArea.pressed
            PropertyChanges {
                target: foo
                prop1: 1
                prop2: 1
                prop3: 1
            }
        }
    ]
    transitions: [
        Transition {
            to: "*"
            NumberAnimation {
                target: foo
                properties: "prop1,prop2,prop3"
                duration: 1000
            }
        }
    ]
    

    This works, but requires me to redundantly specify properties: "prop1,prop2,prop3" when the properties to change are already specified in the PropertyChanges elements. Also, I need to redundantly specify target: foo in NumberAnimation when it's already specified in the PropertyChanges elements.

    Can this redundancy be avoided? If not, why not?

    R 1 Reply Last reply
    1
    • Stefan Monov76S Stefan Monov76

      My code:

      states: [
          State {
              name: "pressed"; when: mouseArea.pressed
              PropertyChanges {
                  target: foo
                  prop1: 10
                  prop2: 10
                  prop3: 10
              }
          },
          State {
              name: "notPressed"; when: !mouseArea.pressed
              PropertyChanges {
                  target: foo
                  prop1: 1
                  prop2: 1
                  prop3: 1
              }
          }
      ]
      transitions: [
          Transition {
              to: "*"
              NumberAnimation {
                  target: foo
                  properties: "prop1,prop2,prop3"
                  duration: 1000
              }
          }
      ]
      

      This works, but requires me to redundantly specify properties: "prop1,prop2,prop3" when the properties to change are already specified in the PropertyChanges elements. Also, I need to redundantly specify target: foo in NumberAnimation when it's already specified in the PropertyChanges elements.

      Can this redundancy be avoided? If not, why not?

      R Offline
      R Offline
      Roumed
      wrote on last edited by Roumed
      #2

      @Stefan-Monov76 At firstly since you have the single target you don't need to specify target property at transition.
      At secondly you can use a specific animators, such as OpacityAnimator, ScaleAnimator, etc.

      You have to set explicitly all names of properties because this is what you want. In some cases you might want not to animate prop1.
      And this is default reaction of the engine: make change without transition (this is about performance).

      You can read more about it here: http://doc.qt.io/qt-5/qtquick-statesanimations-topic.html

      Also, you don't need to make an array if you have a single object, you don't need to explicitly set to property, it's not necessary to give a name to a state since you have when condition. And etc.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Tusovshik
        wrote on last edited by
        #3

        Set explicitly all names of properties because this is what you want. In some cases you might want not to animate prop1.
        And this is default reaction of the engine: make change without transition (this is about performance).

        1 Reply Last reply
        -2

        • Login

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