qt - How to switch to another state at the end of a transition in QML? -


i'm trying implement fitness application displays current exercise name shows progress bar during resting periods. when progress bar filled, name of next exercise displayed, progress bar shown when completed, , on.

note i'm using progress bar example i'll have own widget in real application.

my system has 2 states :

  • exercise value of progress bar 0 , stays 0
  • rest value of progress bar goes 0 maximumvalue on duration of resting period

so goes :

  1. the application in "exercise" state , shows name of current exercicse
  2. the user execute exercise , click on progress bar when he's done
  3. the application switches "rest" state
  4. the user rests while progress bar being completed
  5. after progress bar completed application switches "exercise" state , displays name of next exercise

my issue step 5 : not know how switch state @ end of transition. i've tried change "state" property during propertychanges , time @ end of transition sequentialanimation, error message :

qml stategroup: can't apply state change part of state definition.

here sample code :

import qtquick 2.0 import qtquick.controls 1.1  progressbar {     id: root      width: 200     height: 48      minimumvalue: 0     maximumvalue: 100     value: 76      function switchstate() {         if (state == "exercise")         {             state = "rest"             return         }          if (state == "rest")         {             state = "exercise"             return         }     }      state: "exercise"      states: [         state {             name: "exercise"             propertychanges {                 target: root                 value: 0             }         },         state {             name: "rest"             propertychanges {                 target: root                 value: maximumvalue                  // error: qml stategroup: can't apply state change part of state definition.                 // state: "exercise"             }         }     ]      transitions: [         transition {             to: "rest"             propertyanimation {                 target: root                 properties: "value"                 duration: 1000             }         }     ]      mousearea {         anchors.fill: parent         onclicked: parent.switchstate()     } } 

how can switch state @ end of state transition ?

i believe can using runningchanged signal transition:

transitions: [     transition {         to: "rest"         propertyanimation {             target: root             properties: "value"             duration: 1000         }          onrunningchanged: {             if ((state == "rest") && (!running))                 switchstate();         }     } ] 

qml objects have associated signal property changes (on<property>changed). associated handlers not documented in objects' references, implicitly available due property's existence. see this.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -