Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change the text of the label



  • Hi!
    How to change the text of the label?
    I get the error: page1Label2 is not defined
    Page1Form.ui.qml:

    import QtQuick 2.4
    import QtQuick.Controls 2.4
     
    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: 340
            width: 156
            height: 56
            text: qsTr("Побед: 0%")
            font.pointSize: 20
            horizontalAlignment: Text.AlignHCenter
        }
     
        Label {
            id: page1Label2
            x: 122
            y: 409
            width: 156
            height: 56
            text: qsTr("1 из 20")
            horizontalAlignment: Text.AlignHCenter
            font.pointSize: 20
        }
        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"
            }
        ]
    }
    

    Page1.qml:

    import QtQuick 2.4
    import QtQml 2.12
     
    Page1Form {
     
        page1Button0.onClicked: //left button
        {  
            page1Label2.text = "weg"
        }
     
    }
    

  • Moderators

    @Mikeeeeee said in How to change the text of the label:

    property alias page1ButtonMenu: page1ButtonMenu
    

    You probably need to add an alias for it, like you do for the buttons etc.

    Not sure, I'm not using that .ui.qml weirdness.


Log in to reply