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. Change states.

Change states.

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k 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.
  • O Offline
    O Offline
    oosavu
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      Alek Śmierciak
      wrote on last edited by
      #2

      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
      0
      • O Offline
        O Offline
        oosavu
        wrote on last edited by
        #3

        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
        0
        • A Offline
          A Offline
          Alek Śmierciak
          wrote on last edited by
          #4

          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
          0
          • O Offline
            O Offline
            oosavu
            wrote on last edited by
            #5

            “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
            0

            • Login

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