How to move to another state when you press the button



  • 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"
    }
    

  • Qt Champions 2017

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

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



  • ```
    

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.