qml.ui file states



  • I am trying to do an aplication with qml form item.
    so my UI page would have a bounch of text fields wich would be marked readonly. With the state of the main item changed to edit, the fields would have to be readwrite.

    Since scripts are not supported in the ui file i was wondering how to put the logic for the state transition to the seprate file.

    I have tryed all kinds of stuff but no one givs any results
    Page1Form.ui.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    import Qt.labs.calendar 1.0
    import QtQuick.Layouts 1.12

    ColumnLayout {
    spacing: 2
    id: mainPage
    property alias mainPage: mainPage
    property alias datumText: datumText

    TextField {
    id: datumText
    Layout.minimumWidth: 250
    Layout.preferredWidth: 250
    placeholderText: qsTr("Vnestite datum")
    readOnly: true
    }
    }

    Page1.qml:

    import QtQuick 2.12
    Page1Form{
    mainPage:{
    states: [
    State {
    name: "edit state"

            PropertyChanges {
                target: datumText
                readOnly:false
    
            }
    

    }]
    }

    but when I try to change the state nothing happens to the UI.

    I wold appriciate one example to see how this things have to be written.

    Thank you.
    Best regards Andrej


  • Qt Champions 2017

    How & where you are using the Page1.qml ? Where are you creating the object of Page1.qml ?



  • Icreate my page1form in main.qml
    inside a stackview.

    ApplicationWindow {
    visible: true
    width: 640
    height: 1134
    title: qsTr("Optika")

    StackView {
        id: stackView
        anchors.fill: parent
    
        Page1Form{
            id: optikaPage
        }
    }
    

    }

    br, andrej