How to file a some element in ListView?
-
I have 10 item in ListView.
I want in fifth item change color or call function
How can I do it? -
Hi,
Are you using ListModel ? If so, then you can get the particulat Item using "get":http://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html#get-method and then access its properties.
-
But in model I can not call the function
-
Right. To change something like color you can use that way and to call a function you will need to that in delegate.
@
function getColor(index) {
return "red"
}delegate: Rectangle {
color: getColor(index)
}
@ -
I have item:
@
delegate: Rectangle {
//---
function changedColor(c) {
}
//---
}
@How I can call function changedColor(c) if I know index item?
-
Maybe like this:
@
listview.currentIndex=1 // 1 is index which you know, listview = id of ListView
console.log(listview.currentItem.changedColor())
@ -
Yes, this is it. Thank you