Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PyQt: QListView how to retrieve selected items?

Reply
Thread Tools

PyQt: QListView how to retrieve selected items?

 
 
Flavio
Guest
Posts: n/a
 
      02-02-2006
Hi,

I have a QListview widget that allows me to store a bunch of strings in
it. This strings can be visualized, sorted, selected, etc.

My Problem is that I cant find a way to get the user selected items
back from it! I looked over the Qt documentation many times over but
there is no method to that end.

Any PyQt guru lurking around?

should I try some other list widget, that has a "getSelected()"method?
Is there one?

any help will be appreciated.

Flavio

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      02-02-2006
Flavio schrieb:
> Hi,
>
> I have a QListview widget that allows me to store a bunch of strings in
> it. This strings can be visualized, sorted, selected, etc.
>
> My Problem is that I cant find a way to get the user selected items
> back from it! I looked over the Qt documentation many times over but
> there is no method to that end.
>
> Any PyQt guru lurking around?
>
> should I try some other list widget, that has a "getSelected()"method?
> Is there one?


QListViewItem.isSelected()? You have to loop over the items to get the
ones selected.

Additionally, you might want to register for the

selectionChanged

signal. In Single-selection-mode there even is a overloaded version that
directly gives you the selected item.

And all of this can be found within 20 seconds in the great Qt-Docs.
Especially easy with the included QAssistant, a help-browser with
indexing and whatever...

Diez
 
Reply With Quote
 
 
 
 
Fabian Steiner
Guest
Posts: n/a
 
      02-02-2006
Hi!

Sorry for adopting your post for my own question, but since it is
related to PyQT I think it's ok: Does anybody of you know where the
openbook »GUI Programming with Python: QT Edition« has gone? It's not
available any more: http://www.opendocs.org/pyqt/ points now to a
non-existing site.

So far, I also couldn't find any other site to have a look at the online
version.

Any hints are welcome!
 
Reply With Quote
 
Flavio
Guest
Posts: n/a
 
      02-02-2006
Iterating over the items and checking if it is selected, sounds like a
good idea, but there no obvious way to get a hold of the list of
items!! The only way you can get an item is if you are in single
selection mode and you call selectedItem(). But I have to use multiple
selection mode, for which this method does not work (it says so in the
docs)

The signal selectionChanged() is emitted whenever the set of selected
items has changed but does not return any information regarding the
items comprising the set. Also useless.

> And all of this can be found within 20 seconds in the great Qt-Docs.
> Especially easy with the included QAssistant, a help-browser with
> indexing and whatever...


The docs are really great, it's this particular widget that appear to
lacking some important functionality! This is very sad.

 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      02-02-2006
Flavio schrieb:
> Iterating over the items and checking if it is selected, sounds like a
> good idea, but there no obvious way to get a hold of the list of
> items!! The only way you can get an item is if you are in single
> selection mode and you call selectedItem(). But I have to use multiple
> selection mode, for which this method does not work (it says so in the
> docs)


Who has created these items? Obviously you, so you _can_ store the list
of selected items.

Or you use the equally well documented QListViewItemIterator to traverse
the list of items.


regards,

Diez
 
Reply With Quote
 
Phil Thompson
Guest
Posts: n/a
 
      02-02-2006
On Thursday 02 February 2006 9:25 pm, Fabian Steiner wrote:
> Hi!
>
> Sorry for adopting your post for my own question, but since it is
> related to PyQT I think it's ok: Does anybody of you know where the
> openbook »GUI Programming with Python: QT Edition« has gone? It's not
> available any more: http://www.opendocs.org/pyqt/ points now to a
> non-existing site.
>
> So far, I also couldn't find any other site to have a look at the online
> version.
>
> Any hints are welcome!


I've been told that this is temporary. The book will be back, but I don't know
when.

Phil
 
Reply With Quote
 
Flavio
Guest
Posts: n/a
 
      02-02-2006
> 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...

Thanks Diez!

 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      02-02-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
QListView and text Vojta Drbohlav Python 0 08-16-2006 03:43 PM
Removing an item from a QListView in PyQt Svenn Bjerkem Python 2 04-11-2006 10:38 PM
pyqt: multiple selections in QListView Bob Parnes Python 5 07-16-2004 12:33 PM
fast QListView numerical sort Uwe Mayer Python 2 02-12-2004 09:06 PM



Advertisments