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. States and transitions
QtWS25 Last Chance

States and transitions

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 634 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.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by
    #1

    Hi all,

    I want to test this example and wrote the code below without the Grid part. The problem is that, the rectangle doesn't move like the example! I don't know why! Any idea?

    import QtQuick
    import QtQuick.Window
    
    Window {
        width: 800
        height: 600
        visible: true
    
        Rectangle {
            id: page
            width: 320; height: 480
            color: "lightgray"
    
            Text {
                id: helloText
                text: "Hello world!"
                y: 30
                anchors.horizontalCenter: page.horizontalCenter
                font.pointSize: 24; font.bold: true
    
                MouseArea { id: mouseArea; anchors.fill: parent }
    
                states: State {
                    name: "down"; when: mouseArea.pressed == true
                    PropertyChanges {
                        helloText {
                            y: 160
                            rotation: 180
                            color: "red"
                        }
                    }
                }
    
                transitions: Transition {
                    from: ""; to: "down"; reversible: true
                    ParallelAnimation {
                        NumberAnimation { properties: "y,rotation"; duration: 500; easing.type: Easing.InOutQuad }
                        ColorAnimation { duration: 500 }
                    }
                }
            }
        }
    }
    
    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2

      What rectangle?, it's the text that moves. Press and hold the text.

      You can re- add the Grid/Cells, as they are not important to the text movement. The only thing they do when one is pressed, is change the colour of the text, but the text is set to to turn red when upside down.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      Q 1 Reply Last reply
      1
      • MarkkyboyM Markkyboy

        What rectangle?, it's the text that moves. Press and hold the text.

        You can re- add the Grid/Cells, as they are not important to the text movement. The only thing they do when one is pressed, is change the colour of the text, but the text is set to to turn red when upside down.

        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by
        #3

        @Markkyboy
        That's right. I thought pressed and clicked are the same but they are not.

        What if I want to move the text when it's clicked? I use mouseArea.clicked === true but it's no influence!

        The last question: Isn't using helloText that way inside the PropertyChanges correct? The program works properly but Qt Creator put a red line under it in the code and says: *Invalid property name "helloText"!

        MarkkyboyM 1 Reply Last reply
        0
        • Q qcoderpro

          @Markkyboy
          That's right. I thought pressed and clicked are the same but they are not.

          What if I want to move the text when it's clicked? I use mouseArea.clicked === true but it's no influence!

          The last question: Isn't using helloText that way inside the PropertyChanges correct? The program works properly but Qt Creator put a red line under it in the code and says: *Invalid property name "helloText"!

          MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by Markkyboy
          #4

          @qcoderpro - yes, I neglected to point that out that 'mistake' in the example and went with intuition and made a subtle change to that nonsense little bit of code, as follows;

          PropertyChanges { target: helloText; y: 460; rotation: 180; color: "red" }
          

          I've compiled the code in SailfishSDK for my Sony Xperia 10ii device, with the given tweaks, it works as expected. Screenshot_20230601_002.png

          P.S. I'll play around with the pressed/clicked mouse part. I hadn't given it a thought and missed it in your question. I'll post my findings if any... maybe the animation needs to be different for automated text movement.

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          Q 1 Reply Last reply
          0
          • MarkkyboyM Markkyboy

            @qcoderpro - yes, I neglected to point that out that 'mistake' in the example and went with intuition and made a subtle change to that nonsense little bit of code, as follows;

            PropertyChanges { target: helloText; y: 460; rotation: 180; color: "red" }
            

            I've compiled the code in SailfishSDK for my Sony Xperia 10ii device, with the given tweaks, it works as expected. Screenshot_20230601_002.png

            P.S. I'll play around with the pressed/clicked mouse part. I hadn't given it a thought and missed it in your question. I'll post my findings if any... maybe the animation needs to be different for automated text movement.

            Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by
            #5

            @Markkyboy
            Yes, it's a bit strange that this name: "down"; when: mouseArea.clicked === true doesn't work as expected.

            MarkkyboyM 1 Reply Last reply
            0
            • Q qcoderpro

              @Markkyboy
              Yes, it's a bit strange that this name: "down"; when: mouseArea.clicked === true doesn't work as expected.

              MarkkyboyM Offline
              MarkkyboyM Offline
              Markkyboy
              wrote on last edited by
              #6

              @qcoderpro - down is part of mouse.pressed, not mouse.clicked as far as I can glean.
              So many things about Qt/QML often don't make sense, I just stumble through most if it ;)

              Don't just sit there standing around, pick up a shovel and sweep up!

              I live by the sea, not in it.

              Q 1 Reply Last reply
              0
              • MarkkyboyM Markkyboy

                @qcoderpro - down is part of mouse.pressed, not mouse.clicked as far as I can glean.
                So many things about Qt/QML often don't make sense, I just stumble through most if it ;)

                Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #7

                @Markkyboy
                You mean if we change the name to something else, such as, "move", then mouseArea.clicked === true will work!? I don't think so!

                MarkkyboyM 1 Reply Last reply
                0
                • Q qcoderpro

                  @Markkyboy
                  You mean if we change the name to something else, such as, "move", then mouseArea.clicked === true will work!? I don't think so!

                  MarkkyboyM Offline
                  MarkkyboyM Offline
                  Markkyboy
                  wrote on last edited by
                  #8

                  @qcoderpro - me neither.

                  What version of Qt are you using?, Qt5 or Qt6?, I'm stuck with Qt5 for now.

                  Regarding name: "down"...bla/bla. Have a little squint at the docs for State and its elements; https://doc.qt.io/qt-6/qml-qtquick-state.html ~ it even gives a mouse.clicked in the example.

                  Don't just sit there standing around, pick up a shovel and sweep up!

                  I live by the sea, not in it.

                  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