PDA

View Full Version : changing state of previously selected list item



tyrnikeisari
24th March 2011, 16:41
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.

wladek
25th March 2011, 08:42
Hi tyrnikeisari,

You can try to access the attached property "view" of the QML ListView element from your delegate ListView.view (http://doc.trolltech.com/latest/qml-listview.html#view-prop).

So in your delegate, when drawing the "selected" item you can use a condition like:

if (ListView.view.currentIndex == index)

Hope this is useful.

Regards,
Wladek

tyrnikeisari
26th March 2011, 07:47
Hi Wladek

Thanks for your reply.

I added the check when focus changes and that did the trick. I have in my delegate item:


onFocusChanged: {
if(listView.currentIndex == index){
delegateItem.state = 'selected';
}
else{
delegateItem.state = 'deselected';
}
}



br,
Tyrnikeisari