Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get TextField data entered in listview delegate manually.
Forum Updated to NodeBB v4.3 + New Features

Get TextField data entered in listview delegate manually.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 3 Posters 661 Views
  • 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.
  • T Offline
    T Offline
    track
    wrote on last edited by
    #1

    How can I access the data which I enter I schoolMarkEntery TextField. Please assist in accessing manually entered data in delegate if possible.

    ListView {
    id: listviewStudentMarks
    anchors.fill: parent
    model: modelItems
    
        // anchors.top: parentBoxMarks.bottom
    
    
    /////
    
    // When scroll end align to the nearest item
    snapMode: ListView.SnapToItem
    // Clip painting to his own bounding rectangle to avoid display
    // data outside specified size during flick
    clip: true
    //model: 100
    
    // Increase Flick speed
    maximumFlickVelocity: 10000
    cacheBuffer:1000
    
    ScrollBar.vertical: ScrollBar {
      id: verticalScrollBarMarks
      active: pressed || listviewStudentMarks.moving
      orientation: Qt.Vertical
      opacity: active ? 1:0
      Behavior on opacity {NumberAnimation {duration: 500}}
    
      contentItem: Rectangle {
          implicitWidth: 4
          radius:2
          implicitHeight: parent.height
          color: "#ff00b374"
      }
    }
    
    
    
    
    //////
    
    
    delegate: Rectangle{
     id:stuInfoWeapMarks
    width: root.width
    height: root.height*0.1
    //color:"green"
    
    color:"#73a580"
    // border.color: "white"
    border.color: "#3e363f"
    
    
    // anchors.horizontalCenter: listviewStudent.horizontalCenter
    
    
    
    
    Row{
     id:stuColMarks
     spacing: 2
     anchors.verticalCenter: stuInfoWeapMarks.verticalCenter
    
    
     //
    
    
     //
    
    
     TextField {
         id: schoolMarkEntery
         width: (studentsDelegatenhyhnhMarks.width*0.25);
         height:  (studentsDelegatenhyhnhMarks.height*0.1);//-amount.height)
    
         placeholderText: qsTr("Mark")
    
         //  onTextChanged: model.text = text
    
    
     }
    
     Text {
             // text: modelCheckBoxes.text
    
              text:  " "+(index+1)+". "+listdata11t;
    
              font: modelCheckBoxesMarks.font
              opacity: enabled ? 1.0 : 0.3
              color: modelCheckBoxesMarks.down ? "#000000" : "#ffffff"
             // color: modelCheckBoxes.down ? "#ffffff" : "#000000"
    
    
              verticalAlignment: Text.AlignVCenter
              leftPadding: modelCheckBoxesMarks.indicator.width + modelCheckBoxesMarks.spacing
          }
    
    
    
    
    }
    
    
    
    
    
    }
    
    }
    
    
    1 Reply Last reply
    0
    • B Online
      B Online
      Bob64
      wrote on last edited by
      #2

      @track exact details depend on your model.

      For example, if you are using the QML built-in ListModel, you would use the setData method. See the documentation for an example (the section headed "Modifying List Models").

      If you have a C++ model subclassing QAbstractListModel, note this comment in the documentation:

      For editable list models, you must also provide an implementation of setData(), and implement the flags() function so that it returns a value containing Qt::ItemIsEditable.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        track
        wrote on last edited by
        #3

        The model is qml build in listmodel like this

        ListModel {
        
        id: modelItems
        }
        

        It filled with json data from serverin a for loop like this

             var data = JSON.parse(http.responseText);
        
        
          for(var i = 0; i < data.length; i++)
                 {
        
                     if(data[i].State==="x"){
        
        
        
        
                  //   studentName =data[i].Position+" Name: \n"+data[i].FirstName+" "+data[i].LastName
                     modelItems.append( {listdata11t:
                                         //  data[i].Position+" Name: "+data[i].FirstName+" "+data[i].LastName
        
        
                                             data[i].FirstName+" "+data[i].LastName+
        
        
        
                                             "\n     No: "+data[i].empTel
        
        
        
        
                                       })
        }
        }
        

        The data is presented in the model like this

        modelDisplay.JPG

        I want to insert the mark in TextField with placeholder 'Mark' inside this delegate

        delegate: Rectangle{
         id:stuInfoWeapMarks
        width: root.width
        height: root.height*0.1
         
        color:"#73a580"
         border.color: "#3e363f"
        
         
        
        
        Row{
         id:stuColMarks
         spacing: 2
         anchors.verticalCenter: stuInfoWeapMarks.verticalCenter
        
         
        
         TextField {
             id: schoolMarkEntery
             width: (studentsDelegatenhyhnhMarks.width*0.25);
             height:  (studentsDelegatenhyhnhMarks.height*0.1);
             focus: stuInfoWeapMarks.ListView.isCurrentItem
        
             placeholderText: qsTr("Mark")
           
        
         }
        
         Text {
         
                  text:  " "+(index+1)+". "+listdata11t;
        
                   opacity: enabled ? 1.0 : 0.3
                
        
        
                  verticalAlignment: Text.AlignVCenter
               
              }
        
        
        
        
        }
        
        
        
        
        
        }
        
        

        The Textfield has no model data but the mark that will be inserted is for that person. How can TextField be indexed so that i can use model functions as in the docs. and send back to the server after pressing submit button.

        B 1 Reply Last reply
        0
        • T track

          The model is qml build in listmodel like this

          ListModel {
          
          id: modelItems
          }
          

          It filled with json data from serverin a for loop like this

               var data = JSON.parse(http.responseText);
          
          
            for(var i = 0; i < data.length; i++)
                   {
          
                       if(data[i].State==="x"){
          
          
          
          
                    //   studentName =data[i].Position+" Name: \n"+data[i].FirstName+" "+data[i].LastName
                       modelItems.append( {listdata11t:
                                           //  data[i].Position+" Name: "+data[i].FirstName+" "+data[i].LastName
          
          
                                               data[i].FirstName+" "+data[i].LastName+
          
          
          
                                               "\n     No: "+data[i].empTel
          
          
          
          
                                         })
          }
          }
          

          The data is presented in the model like this

          modelDisplay.JPG

          I want to insert the mark in TextField with placeholder 'Mark' inside this delegate

          delegate: Rectangle{
           id:stuInfoWeapMarks
          width: root.width
          height: root.height*0.1
           
          color:"#73a580"
           border.color: "#3e363f"
          
           
          
          
          Row{
           id:stuColMarks
           spacing: 2
           anchors.verticalCenter: stuInfoWeapMarks.verticalCenter
          
           
          
           TextField {
               id: schoolMarkEntery
               width: (studentsDelegatenhyhnhMarks.width*0.25);
               height:  (studentsDelegatenhyhnhMarks.height*0.1);
               focus: stuInfoWeapMarks.ListView.isCurrentItem
          
               placeholderText: qsTr("Mark")
             
          
           }
          
           Text {
           
                    text:  " "+(index+1)+". "+listdata11t;
          
                     opacity: enabled ? 1.0 : 0.3
                  
          
          
                    verticalAlignment: Text.AlignVCenter
                 
                }
          
          
          
          
          }
          
          
          
          
          
          }
          
          

          The Textfield has no model data but the mark that will be inserted is for that person. How can TextField be indexed so that i can use model functions as in the docs. and send back to the server after pressing submit button.

          B Online
          B Online
          Bob64
          wrote on last edited by
          #4

          @track The index is visible in your TextField as it is a child of the delegate.

          You should simply be able to call setProperty on your model:

               TextField {
                   ...
                   onTextChanged {
                       modelItems.setProperty(index, "mark", text);
                   ...
               }
          

          I assumed you had a mark field in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly.

          GrecKoG 1 Reply Last reply
          0
          • B Bob64

            @track The index is visible in your TextField as it is a child of the delegate.

            You should simply be able to call setProperty on your model:

                 TextField {
                     ...
                     onTextChanged {
                         modelItems.setProperty(index, "mark", text);
                     ...
                 }
            

            I assumed you had a mark field in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly.

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            @Bob64 said in Get TextField data entered in listview delegate manually.:

            @track The index is visible in your TextField as it is a child of the delegate.

            You should simply be able to call setProperty on your model:

                 TextField {
                     ...
                     onTextChanged {
                         modelItems.setProperty(index, "mark", text);
                     ...
                 }
            

            I assumed you had a mark field in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly.

            or just do onTextEdited: model.mark = text

            B 1 Reply Last reply
            0
            • GrecKoG GrecKo

              @Bob64 said in Get TextField data entered in listview delegate manually.:

              @track The index is visible in your TextField as it is a child of the delegate.

              You should simply be able to call setProperty on your model:

                   TextField {
                       ...
                       onTextChanged {
                           modelItems.setProperty(index, "mark", text);
                       ...
                   }
              

              I assumed you had a mark field in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly.

              or just do onTextEdited: model.mark = text

              B Online
              B Online
              Bob64
              wrote on last edited by
              #6

              @GrecKo thanks for the simplification. I have not often used a directly edited ListModel (my models tend to be C++ with custom modification APIs) and I have always followed the approach suggested by the example in the Qt ListModel doc. Interesting that they made it seem harder than it needs to be!

              1 Reply Last reply
              0
              • T Offline
                T Offline
                track
                wrote on last edited by
                #7

                Thanks too.

                The listmodel is like this

                ListModel {
                
                id: modelItems
                
                
                //ListElement{
                  //  mark:""
                //}
                }
                
                

                I tried to add the ListElement 'mark' to the ListModell modelitems and when the data is supposed to be uploaded in this forloop

                 for(var i = 0; i < data.length; i++)
                         {
                
                             if(data[i].State==="x"){
                
                
                
                
                              modelItems.append( {
                                                   listdata11t:
                                                 //  data[i].Position+" Name: "+data[i].FirstName+" "+data[i].LastName
                
                
                                                     data[i].FirstName+" "+data[i].LastName+
                
                
                
                                                     "\n     No: "+data[i].empTel
                
                
                
                
                                               }
                                                )
                }
                
                }
                
                

                It complains that listdata11t is not declared and is found in the text element of the delegate

                 Text {
                 
                          text:  " "+(index+1)+". "+listdata11t;
                
                           opacity: enabled ? 1.0 : 0.3
                 
                
                          verticalAlignment: Text.AlignVCenter
                       }
                
                

                I don't have an idea of how to set mark for the textfield for this model . The json data appended to the model looks like this
                "[{"FirstName":"Klp","LastName":"Nnjm","employeeLogDID":6,"empTel":"0000000090","empRegDate":"2023-05-21 10:18:30","DepartmentName":"Maths","CategoryType":"Main Branch\/Sub Department\/(etc)","Position":"Student","GradeStudentStatus":"Accepted","Grade":"Grade 0","BranchName":"Mko High School","DepartmentID":5,"GSRegDate":"2023-05-21 10:16:50","brTel":"0000000000","BusinessName":"Mko High School","dpTel":"0099009900","sGrSbjID":1,"dpType":"Subject","State":"x","Test":"Not Available","Vaciination":"Not Available","vcName":"Not Available","DepartmentTypeID":12,"RegistrationDate":"2023-05-21 10:16:50","LogDataStatusID":7},{"FirstName":"Mnbg","LastName":"Aswe","employeeLogDID":7,"empTel":"0000000099","empRegDate":"2023-05-21 05:07:40","DepartmentName":"Maths","CategoryType":"Main Branch\/Sub Department\/(etc)","Position":"Student","GradeStudentStatus":"Accepted","Grade":"Grade 0","BranchName":"Mko High School","DepartmentID":5,"GSRegDate":"2023-05-21 05:06:40","brTel":"0000000000","BusinessName":"Mko High School","dpTel":"0099009900","sGrSbjID":2,"dpType":"Subject","State":"x","Test":"Not Available","Vaciination":"Not Available","vcName":"Not Available","DepartmentTypeID":12,"RegistrationDate":"2023-05-21 05:06:40","LogDataStatusID":7}]"

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  track
                  wrote on last edited by
                  #8

                  I finally got it to work by creating ths model

                  ListModel {
                  
                  id: modelItemMark
                  
                  ListElement{
                      stuName:""
                  }
                  ListElement{
                      stuNum:""
                  }
                  
                   ListElement{
                       mark:""
                  }
                  
                  
                  
                  }
                  
                  

                  and adding the data in forloop like this

                  modelItemMark.append({
                                           "stuName": data[i].FirstName+" "+data[i].LastName,
                                                   "stuNum": data[i].empTel
                  
                  
                   
                  
                  1 Reply Last reply
                  0
                  • T track has marked this topic as solved on

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved