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. How to move to another state when you press the button

How to move to another state when you press the button

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 568 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Good day!
    How to move to another state when you press the button?
    Here is Page1Form.ui.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.2
     
    Item {
        id: element
        width: 400
        height: 600
        property alias page1Button1: page1Button1
        property alias page1Button0: page1Button0
        property alias page1ButtonMenu: page1ButtonMenu
     
        Button {
            id: page1Button0
            x: 66
            y: 172
            width: 128
            height: 128
            //font.capitalization: Font.AllUppercase
            //display: AbstractButton.TextOnly
            //topPadding: 5
            Image {
                id: image
                width: 130
                height: 130
                anchors.topMargin: 0
                anchors.leftMargin: 0
                anchors.rightMargin: 0
                anchors.bottomMargin: 0
                anchors.fill: parent
                source: "qrc:/images/images/close.png"
                fillMode: Image.Stretch
            }
        }
     
        Button {
            id: page1Button1
            x: 251
            y: 172
            width: 130
            height: 130
            Image {
                id: image1
                width: 130
                height: 130
                anchors.rightMargin: 0
                anchors.bottomMargin: 0
                anchors.fill: parent
                source: "qrc:/images/images/close.png"
                fillMode: Image.Stretch
            }
        }
     
        Button {
            id: page1ButtonMenu
            x: 150
            y: 479
            text: qsTr("МЕНЮ")
            font.pointSize: 18
        }
     
        Label {
            id: page1labe0
            x: 57
            y: 47
            width: 286
            height: 33
            text: qsTr("Выберете красный цвет")
            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: 22
            font.family: "Verdana"
            font.weight: Font.Thin
        }
     
        Label {
            id: page1Label1
            x: 122
            y: 358
            width: 156
            height: 56
            text: qsTr("Побед: 0%")
            font.pointSize: 20
            horizontalAlignment: Text.AlignHCenter
        }
        states: [
            State {
                name: "Page1State1"
     
                PropertyChanges {
                    target: image
                    source: "qrc:/images/images/red.png"
                }
     
                PropertyChanges {
                    target: image1
                    source: "qrc:/images/images/black.png"
                }
            },
            State {
                name: "Page1State2"
     
                PropertyChanges {
                    target: image
                    source: "qrc:/images/images/black.png"
                }
     
                PropertyChanges {
                    target: image1
                    source: "qrc:/images/images/red.png"
                }
            },
            State {
                name: "Page1State0"
            }
        ]
    }
    

    This is Page1.qml

    import QtQuick 2.4
     
    Page1Form {
     
        page1Button1.onClicked: { //rigth button
            //anchors.fill: parent
            //anchors.fill
            //
            //parent.state=="Page1State1"
            //parent.state= "Page1State1"
    }
     
        page1Button0.onClicked: {  //left button
            state: "Page1State0"
        }
     
        page1ButtonMenu.onClicked: {
            loader.source = "Page0.qml"
    }
     
    //state: "Page1State1"
    }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Based on the condition you need to set the state variable. The following statement should work.

      //parent.state=="Page1State1"

      What is the issue ? Is it not working ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by Mikeeeeee
        #3

        @dheerendra said in How to move to another state when you press the button:

        This does not work.
        I need to make it work.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by
          #4
          ```
          

          page1Button0.onClicked: { //left button
          state = "Page1State2"
          }

          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