Access item inside ListView via delegate
-
wrote on 25 Jan 2021, 05:23 last edited by Ratzz
I was able to access the
TextEdit
value usingproperty
value which is set to model viaListElement
something like thisListElement { editProperty: "Initial text" }
and on click event
onClicked: { listModel.setProperty(index, "editProperty", editField.text) }
Still I am unable to access the delete
Button
. Does anyone know to access it? -
I was able to access the
TextEdit
value usingproperty
value which is set to model viaListElement
something like thisListElement { editProperty: "Initial text" }
and on click event
onClicked: { listModel.setProperty(index, "editProperty", editField.text) }
Still I am unable to access the delete
Button
. Does anyone know to access it?hi @Ratzz
you already "listen" to the listModel count property for your onClicked why don't you make the visible property depending on it as well ?
Column { width: 100 Button { text: "Delete" visible: listModel.count > 1 onClicked:{ if(listModel.count > 1) listModel.remove(index); } } }
-
hi @Ratzz
you already "listen" to the listModel count property for your onClicked why don't you make the visible property depending on it as well ?
Column { width: 100 Button { text: "Delete" visible: listModel.count > 1 onClicked:{ if(listModel.count > 1) listModel.remove(index); } } }
wrote on 25 Jan 2021, 07:03 last edited by@J-Hilk said in Access item inside ListView via delegate:
you already "listen" to the listModel count property for your onClicked why don't you make the visible property depending on it as well ?
It just worked :) Thank you @J-Hilk
-
I was able to access the
TextEdit
value usingproperty
value which is set to model viaListElement
something like thisListElement { editProperty: "Initial text" }
and on click event
onClicked: { listModel.setProperty(index, "editProperty", editField.text) }
Still I am unable to access the delete
Button
. Does anyone know to access it?wrote on 25 Jan 2021, 07:05 last edited by@Ratzz said in Access item inside ListView via delegate:
I was able to access the TextEdit value using property value which is set to model via ListElement something like this
@J-Hilk , Is there any better way than this ?
-
@Ratzz said in Access item inside ListView via delegate:
I was able to access the TextEdit value using property value which is set to model via ListElement something like this
@J-Hilk , Is there any better way than this ?
@Ratzz
for example, you could just bind the text directly:Column { width: 50 TextEdit { text: editableText} } ... ... ListModel { id: listModel ListElement { editableText: "SomeText" } }
-
wrote on 25 Jan 2021, 07:18 last edited by
That works as well
-
@Ratzz
for example, you could just bind the text directly:Column { width: 50 TextEdit { text: editableText} } ... ... ListModel { id: listModel ListElement { editableText: "SomeText" } }
wrote on 25 Jan 2021, 12:04 last edited by Ratzz@J-Hilk
Now when I tried with empty textListModel { id: listModel ListElement { editableText: "" } }
and then I tried to change the text field value manually say "sometext" . Button event returned null
onClicked: { listModel.get(0).editableText console.log(listModel.get(0).editableText ) //Null }
while button event setting property gave proper result
onClicked: { listModel.setProperty(index, "editableText ", id.text) console.log(listModel.get(0).editableText ) //"sometext" }
-
@J-Hilk
Now when I tried with empty textListModel { id: listModel ListElement { editableText: "" } }
and then I tried to change the text field value manually say "sometext" . Button event returned null
onClicked: { listModel.get(0).editableText console.log(listModel.get(0).editableText ) //Null }
while button event setting property gave proper result
onClicked: { listModel.setProperty(index, "editableText ", id.text) console.log(listModel.get(0).editableText ) //"sometext" }
@Ratzz interesting
I usually have c++ based models, so my experience with QML models is limited 😕
Maybe someone else know more about this behavior
-
@Ratzz interesting
I usually have c++ based models, so my experience with QML models is limited 😕
Maybe someone else know more about this behavior
wrote on 25 Jan 2021, 13:35 last edited by Ratzz@J-Hilk
okay Fine. -
@J-Hilk
Now when I tried with empty textListModel { id: listModel ListElement { editableText: "" } }
and then I tried to change the text field value manually say "sometext" . Button event returned null
onClicked: { listModel.get(0).editableText console.log(listModel.get(0).editableText ) //Null }
while button event setting property gave proper result
onClicked: { listModel.setProperty(index, "editableText ", id.text) console.log(listModel.get(0).editableText ) //"sometext" }
@Ratzz said in Access item inside ListView via delegate:
listModel.get(0).editableText
What is that line supposed to do? You are not modifying anything here
onClicked: { listModel.setProperty(index, "editableText ", textEdit.text) }
just do that instead:
onClicked: editableText = textEdit.text
-
@GrecKo , Yes I can do that as well.
How can I get the updated text "editableText" as soon I change the value of
TextEdit
is changed?@Ratzz
console.log(editableText )
, you have access to the role values (as context properties) corresponding to the model cell in the delegate
11/14