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. QML States : Not able to see any transition, rectangle always remains in state1
Forum Updated to NodeBB v4.3 + New Features

QML States : Not able to see any transition, rectangle always remains in state1

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 3.5k 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.
  • S Offline
    S Offline
    sonal1687
    wrote on last edited by
    #1

    Code :

    @
    import QtQuick 1.0
    import com.nokia.meego 1.0

    PageStackWindow {
    id: rootWindow
    initialPage: page1

    Page {
        id: page1
        anchors.fill: parent
    
    
        Rectangle {
            id: rectItem
            width: 20
            height: 20
            color: "Red"
        }
    
    
        states: [
            State {
                name: "state1"
                PropertyChanges {
                    target: rectItem; x: 0; y:20
                }
            },
            State {
                name: "state2"
                PropertyChanges {
                    target: rectItem; x: 100; y: 100
                }
            }
        ]
    
        state: "state1"
    
        transitions: [
            Transition {
                from: "state1"
                to: "state2"
                PropertyAnimation { duration: 1000; properties: "x";
                    easing.type: Easing.InOutQuad }
            }
        ]
        Component.onCompleted: {
            timer.running = true;
        }
    }
    Timer {
        id: timer
        interval: 3000; running: false; repeat: true
        triggeredOnStart: true
        onTriggered: {
            console.log("timer")
            state = state === "state2" ? "state1" : "state2"
            console.log(state +  "state");
        }
    }
    

    }
    @

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sonal1687
      wrote on last edited by
      #2

      Sorry for previous formatting error , please find code below and please help me

      [EDIT: removed doubled code. Please edit the original post (link is to the right, below username and avatar) to change it in the future, thanks. Volker]

      1 Reply Last reply
      0
      • B Offline
        B Offline
        billouparis
        wrote on last edited by
        #3

        What is this state = state === ?

        I used the following, and it worked!
        @
        state = (state == "state2")? "state1": "state2"
        @

        Enjoy!
        Bill

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sonal1687
          wrote on last edited by
          #4

          Hi Bill,

          Its still not working :( M testing on N9 device.

          Regards,
          Sonal

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="billouparis" date="1329218245"]
            What is this state = state === ?
            [/quote]

            JavaScript has an equality operator <code>==</code> and an identiy operator <code>===</code> - both do comparison, but the latter one not doing implicit type conversion.

            <code>state = state === ... ? ... :</code> is an conditional assignment as known from C++.

            [quote author="sonal1687" date="1329219216"]Its still not working[/quote]

            Do you get any console output so you can make sure the timer is fired?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              billouparis
              wrote on last edited by
              #6

              Ok I tested it so:

              @state = state === "state2" ? "state1": "state2"@
              and it worked too indeed, sorry for this!

              So the issue must be somewhere else. In my case I tested it on desktop PC, and simply removed the Nokia component you're using, and replaced it with a simple Item / Rectangle elements combo.

              Bill

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sonal1687
                wrote on last edited by
                #7

                Ok so it is working in desktop... Yes I do get console output that state is changing after every 3 seconds but I see no visual change in position of rectangle.

                -Sonal-

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sonal1687
                  wrote on last edited by
                  #8

                  I got it : after putting state as page1.state :)

                  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