Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved GridView data

    QML and Qt Quick
    2
    4
    668
    Loading More Posts
    • 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.
    • J
      JasonS last edited by p3c0

      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?

      1 Reply Last reply Reply Quote 0
      • P
        peteritv last edited by

        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) }

        1 Reply Last reply Reply Quote 0
        • J
          JasonS last edited by

          Thanks, that helped me solve my question.

          P 1 Reply Last reply Reply Quote 0
          • P
            peteritv @JasonS last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post