Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Change states.

    QML and Qt Quick
    2
    5
    1316
    Loading More Posts
    • 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.
    • O
      oosavu last edited by

      Hello all!

      1. How can I find out the values of previous state, then state changes?
      2. How to run some script then get out from some state? (analogue of StateChangeScript{}, but run on exit state)

      Example:
      @
      Rectangle{
      id: myrect
      states:[
      state1{name: "state1"; target: myrect; color: "Red"},
      state2{name: "state2"; target: myrect; color: "Green"},
      state3{name: "state3"; target: myrect; color: "Blue"},
      ...
      state10{name: "state10"; target: myrect; color: "Black"},
      ]
      onStateChange:{
      console.log( ) // this is trouble. I need print "color changed from Green to Yello"
      }
      }
      @

      my Qt version is 4.8. QML 1.1.
      sory for bad English.

      1 Reply Last reply Reply Quote 0
      • A
        Alek Śmierciak last edited by

        Hello,

        a quick option to remember a state name is to introduce "a string property to which you would assign":http://qt-project.org/doc/qt-4.8/propertybinding.html a name of the current state on every state change.
        To get the "value" of the previous state, you need to do state name comparisons.

        As for running scripts, you need to specify what would the next state be. QML elements cannot be stateless (they at least have their default state).

        1 Reply Last reply Reply Quote 0
        • O
          oosavu last edited by

          Thanks for reply!

          1. I know this method, but he is bulky. Probably, have to do so..

          2. I not may spesify next state. But i need to run script then go out some state.

          may optionally be another method, without states?
          my real goal is "container" element without Loader:
          @
          MyPage.qml:
          Rectangle{
          //some code
          visible: false
          property variant myExitFunc
          }
          @
          MyContainer.qml:
          @
          Item{
          MyPage{id: r1; myExitFunc: {/code/}}
          MyPage{id: r2; myExitFunc: {/code/}}
          ...
          MyPage{id: r10; myExitFunc: {/code/}}

          states:{
              State{ name:page1
              PropertyChanges:{
                      target: r1
                      visible: true
              }}
          

          ....
          State{ name:page1
          PropertyChanges:{
          target: r10
          visible: true
          }}
          }
          }
          @
          And i not may use onVisibleChanged beacouse MyContainer may be unvisible (Which implies, that myExitFuncshould run 10 times then MyContainer.visible = true).

          UPD: fix error in source code

          1 Reply Last reply Reply Quote 0
          • A
            Alek Śmierciak last edited by

            I am not sure if we understand each other. Every QML element has to have a state. You cannot "go out of state". If you want to implement such a page stack, you need to make the other pages invisible in the state change definition.

            1 Reply Last reply Reply Quote 0
            • O
              oosavu last edited by

              “go out of state” is known "change from state1 to state2".
              in onStateChange() know state2, but not know state1.

              not need making other pages invisible because default value of PropertyChanges.restoreEntryValues is true.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post