473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PyQt: QListView how to retrieve selected items?

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

Feb 2 '06 #1
7 14518
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
Feb 2 '06 #2
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!
Feb 2 '06 #3
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.

Feb 2 '06 #4
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
Feb 2 '06 #5
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
Feb 2 '06 #6
> 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!

Feb 2 '06 #7
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
Feb 2 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: GTi | last post by:
I have a listview that with selected items. But I want to "reselect" items after a refresh. Each items have a uniqe value in the Tag object. After a refresh some new items may be added or removed...
2
by: JP | last post by:
Hi, I am trying to loop through the listbox and read the selected items from the list, within a CLICK event on an aspx page. The following is what I have tried. It loops through the listbox,...
1
by: Peter | last post by:
How can I check which items has been selected in CheckBoxList control when I bind data to it from SQL Server? The code I use works fine when I add manually items into checkboxlist control, but does...
1
by: Robin Tucker | last post by:
Hi ppl, My owner draw list box controls do not "refresh" old selected items when a new selection is made. This means that as you click to make selections, the previously selected items stay...
3
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
1
by: Randy | last post by:
Hi, I have a listbox that allows multiple selections. I need to loop through each selection and execute code based on the text of the item. I'm sure that this is really simple, but I can't quite...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.