PyQt: QListView how to retrieve selected items?

Diez B. Roggisch deets at nospam.web.de
Thu Feb 2 18:28:40 EST 2006


Flavio schrieb:
>> Who has created these items? Obviously you, so you _can_ store the list
>> of selected items.
> 
> well yeah, but the Idea was to let the user select(through the widget)
> a subset of the original list and then access that subset...
> 
>> Or you use the equally well documented QListViewItemIterator to traverse
>> the list of items.
> 
> Alright! Now you've hit the jackpot! I didn't know that class! There is
> no  reference to it in the QListView docs! This can solve my problem
> (combined with isSelected()), though not as elegantly or efficiently as
> having direct access to the set of selected items which already exists
> but is not accessible...

You are wrong thinking that this less efficient - on the contrary. It 
might be less convenient.

The problem is that updating the selected-item-list (which can be a 
tree, mind you!) on every user's click will be O(n). Maybe O(log(n)), 
but that's with tricks and I'd have to think about that.

Additionally, maintaining that list in case of addition, deletion and so 
on will always call for rebuilds.

In the end it might be that your user selects and deselects an item 100 
times. But only when she hits the "export this list"-button you're 
actually interested in the always-up-to-date data. So, efficiency is not 
the problem here.

Diez



More information about the Python-list mailing list