473,395 Members | 1,649 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,395 software developers and data experts.

pyqt: multiple selections in QListView

I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.

Thanks for any help.

Bob Parnes

--
Bob Parnes
rp*****@megalink.net
Jul 18 '05 #1
5 6040
Jim
Bob Parnes wrote:
I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.


I think this will walk through all of the QListViewItems in a QListView
(haven't tried it though) and give you a list of selected items:

def getSelectedItems (listView):
selectedLVIList = []
listViewItem = listView.firstChild()

scan(listViewItem, selectedLVIList)

return selectedLVIList

def scan(listViewItem, selectedLVIList):
while listViewItem:
if listViewItem.isSelected():
selectedLVIList.append(listViewItem)

scan(listViewItem.firstChild())

listViewItem = listViewItem.nextSibling()

The docs say that you might not traverse the list view items in sort order
using firstChild/nextSibling. This also doesn't keep track explicitly of
which level an item is on, although you can trace back each item's
parent(s) (or else modify the code to track that).

Jim
Jul 18 '05 #2
On Tuesday 13 July 2004 1:53 am, Bob Parnes wrote:
I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.


QListViewIterator was added to PyQt v3.9 (current version is v3.12).

Phil
Jul 18 '05 #3
On Tue, Jul 13, 2004 at 08:29:07AM +0100, Phil Thompson wrote:
On Tuesday 13 July 2004 1:53 am, Bob Parnes wrote:
I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.


QListViewIterator was added to PyQt v3.9 (current version is v3.12).

Phil


Thanks very much. I am using v3.8 on a debian computer. I'll try to
upgrade.

Bob
--
Bob Parnes
rp*****@megalink.net
Jul 18 '05 #4
On Wednesday 14 July 2004 11:38 pm, Bob Parnes wrote:
On Tue, Jul 13, 2004 at 08:29:07AM +0100, Phil Thompson wrote:
On Tuesday 13 July 2004 1:53 am, Bob Parnes wrote:
I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.


QListViewIterator was added to PyQt v3.9 (current version is v3.12).

Phil


Thanks very much. I am using v3.8 on a debian computer. I'll try to
upgrade.


At the moment it could be more Pythonic. You have to do something like...

it = QListItemViewIterator(list_view)

itm = it.current()

while itm:
# Do something

it += 1
itm = it.current()

In a future version I will make QListItemViewIterator behave like a Python
iterator so that you do this instead...

for itm in QListItemViewIterator(list_view):
# Do something

Phil
Jul 18 '05 #5
On Tue, 13 Jul 2004 00:25:02 -0700, Jim <ti*********@anyaccount.com> wrote:
Bob Parnes wrote:
I cannot find a reference on identifying multiple selections in
QListView. Apparently one has to iterate through all the items and test
each individually, but I don't know how to do the iteration. The qt3
documentation suggests QListViewItemIterator, but this does not seem to
be available in python.


I think this will walk through all of the QListViewItems in a QListView
(haven't tried it though) and give you a list of selected items:

def getSelectedItems (listView):
selectedLVIList = []
listViewItem = listView.firstChild()

scan(listViewItem, selectedLVIList)

return selectedLVIList

def scan(listViewItem, selectedLVIList):
while listViewItem:
if listViewItem.isSelected():
selectedLVIList.append(listViewItem)

scan(listViewItem.firstChild())

listViewItem = listViewItem.nextSibling()

The docs say that you might not traverse the list view items in sort order
using firstChild/nextSibling. This also doesn't keep track explicitly of
which level an item is on, although you can trace back each item's
parent(s) (or else modify the code to track that).

Jim


Thanks very much, the only error is that the nested call to scan needs
selectedLVList as a second argument. My list has only two levels, and I
do not need to maintain sort order, so this does what I need.

Bob

--
Bob Parnes
rp*****@megalink.net
Jul 18 '05 #6

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

Similar topics

35
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another...
0
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able...
7
by: Flavio | last post by:
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...
2
by: Fabian Steiner | last post by:
Hello! I have got a QMainWindow with a QListView, in which the different entries of a database are shown to the user. Moreover it has got a QPushButton, so that another QDialog can be opened...
2
by: Svenn Bjerkem | last post by:
Hi, I am looking for a bit more elaboration on the problem of deleting elements from a QListsView. I know this is a tricky problem with references, but I have not been able to extract enough...
2
by: Tina I | last post by:
Hi, I'm fairly new to both Python and Qt so please bare with me. I have a QListView with a number of columns. In order to filter the output I iterate using QListViewItemIterator looking for the...
4
by: tbayse | last post by:
Hello, I have a question about making multiple selection queries in Access. I am running windows XP and Access 2003. Up until this point I had a form where a user would make single selections from...
1
by: Reinaldo Carvalho | last post by:
Hi, I programming with qt module and i have a qWidgetTab with a qListView inside, and i need update the qListView every 5 seconds, how do this on transparent mode to user. I do a function to...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.