changing state of previously selected list item
Hi
I have a QML application with ListView and ListModel. When I click an list item I'll change it's state (to "selected") and draw it bit differently. This works just fine.
Next I'll select another item from the list. At this point I would like to change previously selected items state back to "unselected". I know the index of the item, but I can't figure out how to access delegate's state.
How I can do this or is there better approach? I'm just testing and learning how to do things before actually implementing my application.
Re: changing state of previously selected list item
Hi tyrnikeisari,
You can try to access the attached property "view" of the QML ListView element from your delegate ListView.view.
So in your delegate, when drawing the "selected" item you can use a condition like:
Code:
if (ListView.view.currentIndex == index)
Hope this is useful.
Regards,
Wladek
Re: changing state of previously selected list item
Hi Wladek
Thanks for your reply.
I added the check when focus changes and that did the trick. I have in my delegate item:
Code:
onFocusChanged: {
if(listView.currentIndex == index){
delegateItem.state = 'selected';
}
else{
delegateItem.state = 'deselected';
}
}
br,
Tyrnikeisari