Access a property of delegate in listview
Hi,
This is pretty simple but i lost somewhere when i am working on this .Here i post my example.
I need to read a property which is declared inside a delegate from its parent.How do i do ?
Code:
ListView{
id: listView
property bool indeeee: listView.contentItem.childrenRect.check
state: listView.indeeee ? "moved" : ""
delegate: delegateItem
}
Component{
id: delegateItem
Row{
id: rowww
spacing: 20
property bool [COLOR="#FF0000"]check[/COLOR]:index===2 ? true : false
}
}
I tried to read with listView.contentItem.childrenRect.check which says unable to assign undefined to bool
Regards
Bala B
Re: Access a property of delegate in listview
You have to remember the delegate is a component so you don't have one delegate per view but rather one delegate per visible item. To access an item from a view you have ListView.currentItem, ListView.highlightItem or ListView.itemAt.
So for example to know whether the current item is checked, you'd do:
Code:
property bool indeeee: currentItem.check
However often you want to provide a relation in the other direction:
Code:
ListView {
property int checkedIndex: -1
delegate: MouseArea {
// ...
onClicked: ListView.view.checkedIndex = index // upon clicking I become the checked index in the view
}
}
Just remember that only the delegate root (and not its children) has the "ListView" attached property and the "index" property available.