Editing elements of a listmodel -- binding in delegate does not work in both directions ?
-
Hi,
I am trying to get an editor working, and have a problem syncing edited values back to the model.
I hope i am overlooking something simple, maybe you see it ?I have listview showing a ListModel. (See a pruned code fragment below)
The values appear on screen correctly.When I edit the 'value' ( MaPropRow is a custom component, but 'value' esssentially maps to a text field),
this new value is not saved back into the model.I update values in the model with a routine 'loadallvalues' when the screen comes up (Component.onCompleted) and this is updated on screen :
so in this direction binding seems to work : model.value --> value (on screen item in delegate)unfortunately, in the other direction it does not : value edited (on screen item in delegate) ---> model.value
when I edit a 'value' text field, this is not stored back in the model.How can I make this work ?
@
ListView { clip: true model: progedit_model delegate: progedit_delegate } Component { id: progedit_delegate Rectangle{ height: prop_rowinterval width: parent.width color: "transparent" MaPropRow{ y: (parent.height-height)/2 width: parent.width height: prop_height description : model.description value : model.value unit : model.unit propname: model.propname proptype: model.proptype } } } ListModel { id: progedit_model // list elements cannot contain qsTr, need to find a solution for translation ListElement{ description : "Cameras" value : 1 unit : "1 or 3" propname: "cameras" proptype: "int" } ListElement{ description : "Density" value : 0 unit : "_DENSITY" propname: "density" proptype: "int" } ListElement{ description : "Compensation" value : 0 unit : "0.1mm" propname: "slipComp" proptype: "int" } }
@
-
How are you updating delegate ? MouseArea or TextInput or something else ?You need to catch the appropriate signals of the Delegate and modify the model using setProperty. In my example one of the role is 'name'.
e.g
@Component {
Item {
TextInput
{font.pixelSize: 20;
font.bold: true;
text : phone
onEditingFinished:{
console.log("Here ="+index)
listView.model.setProperty(index,"name",text)
}
}
}
ListView {
id :listView}@
-
Hi,
thanks a lot
that makes sense.
I'll try that.