GridView data



  • This is probably QML 101, but I'm having difficulties figuring out how to iterate through or even get values from a GridView. I have a 7x3 GridView made up of delegate I made:

    import QtQuick 2.0
    
    Item{
        id: scheduleDelegate
    
        property string name
        signal trigger(string name)
    
        Column{
            spacing: 5
    
            Text{
                id: columnHeading
                width: 35
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                text: "Wk " + (index + 1)
            }
    
            TextEditNumberInput{
                id: bloom
                textToShow: text1
                }
            }
    
            TextEditNumberInput{
                id: big
                textToShow: text2            
                }
            }
    
            TextEditNumberInput{
                id: tiger
                textToShow: text3            
                }
            }
        }
    }
    

    TextEditNumberInput is as follows:

    import QtQuick 2.0
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    
    TextField{
        id: number
    
        property alias textToShow: number.text
    
        width: 35
        height: 35
    
        Layout.fillHeight: true
        Layout.fillWidth: true
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        padding: 0
    
        text: text
    
        background: Rectangle {
            border.color: "#D3D3D3"
            border.width: 1
            anchors.fill: parent
        }
    
        NumberPad{
            id: numberPad
        }
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                numberPad.x = (width / 5 - numberPad.width / 5 )
                numberPad.y = (height / 2 - numberPad.height / 2)
    
                var numberPadComponent = Qt.createComponent("qrc:/pages/NumberPad.qml");
                if (numberPadComponent.status === Component.Ready) {
                    var dialog = numberPadComponent.createObject(parent);
    
                    numberPad.open()
                }
            }
        }
    
        Connections {
            id: numberPadConnection
            target: numberPad
    
            onVisibleChanged: {
                if(!target.visible){
                    if(!target.returnValue==""){
                        setNumberOfWeeksText();
                    }
                }
            }
    
            function setNumberOfWeeksText(){
                number.text = target.returnValue;
            }
        }
    }
    

    Can someone help explain to me how to get the values from the TextField within my GridView?



  • Since you define a scheduleDelegate signal:
    signal trigger(string name)

    You need to bind some action of your TextEditNumberInput component to that signal?

    So something inside your TextField like:
    onChanged: { trigger(text) }



  • Thanks, that helped me solve my question.



  • @JasonS : Ur welcome! I am just starting QML myself, and us newbies should support eachother :)


Log in to reply
 

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