Get TextField data entered in listview delegate manually.
-
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 } } } } -
@track exact details depend on your model.
For example, if you are using the QML built-in
ListModel, you would use thesetDatamethod. 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.
-
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
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.
-
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
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.
@track The
indexis visible in yourTextFieldas it is a child of the delegate.You should simply be able to call
setPropertyon your model:TextField { ... onTextChanged { modelItems.setProperty(index, "mark", text); ... }I assumed you had a
markfield in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly. -
@track The
indexis visible in yourTextFieldas it is a child of the delegate.You should simply be able to call
setPropertyon your model:TextField { ... onTextChanged { modelItems.setProperty(index, "mark", text); ... }I assumed you had a
markfield in your model as I couldn't really see how your model was structured, so you will need to change that name accordingly.@Bob64 said in Get TextField data entered in listview delegate manually.:
@track The
indexis visible in yourTextFieldas it is a child of the delegate.You should simply be able to call
setPropertyon your model:TextField { ... onTextChanged { modelItems.setProperty(index, "mark", text); ... }I assumed you had a
markfield 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 -
@Bob64 said in Get TextField data entered in listview delegate manually.:
@track The
indexis visible in yourTextFieldas it is a child of the delegate.You should simply be able to call
setPropertyon your model:TextField { ... onTextChanged { modelItems.setProperty(index, "mark", text); ... }I assumed you had a
markfield 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@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 QtListModeldoc. Interesting that they made it seem harder than it needs to be! -
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}]" -
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 -
T track has marked this topic as solved on