472,328 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

PyQt: QListviewItemIterator

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 string
entered by the user (filterString). Currently I do it this way:
it = QListViewItemIterator(self.authListView)
try:
while it:
item = it.current()
if item.text(0).contains(filterString) or
item.text(1).contains(filterString) or item.text(2).contains(filterString):
item.setVisible(1)
else:
item.setVisible(0)
it +=1
except AttributeError:
pass
Basically I iterate through the ListView until it goes beyond the list
and raise an exception, which I catch. It works but to be honest it
looks and feels ugly; "Do something until it goes wrong"

So, question: How can I know I have reached the last item in the QListView?

Thanks
Tina
Jan 16 '07 #1
2 2160
On Tuesday 16 January 2007 18:57, Tina I wrote:
I have a QListView with a number of columns. In order to filter the
output I iterate using QListViewItemIterator looking for the string
entered by the user (filterString). Currently I do it this way:
[Reformatted code for quoting purposes]
it = QListViewItemIterator(self.authListView)
try:
while it:
item = it.current()
if item.text(0).contains(filterString) or \
item.text(1).contains(filterString) or \
item.text(2).contains(filterString):

item.setVisible(1)
else:
item.setVisible(0)
it +=1
except AttributeError:
pass

Basically I iterate through the ListView until it goes beyond the list
and raise an exception, which I catch. It works but to be honest it
looks and feels ugly; "Do something until it goes wrong"

So, question: How can I know I have reached the last item in the
QListView?
When it.current() returns None. You can rewrite what you already
have like this:

it = QListViewItemIterator(self.authListView)
while it.current():
item = it.current()
if item.text(0).contains(filterString) or \
item.text(1).contains(filterString) or \
item.text(2).contains(filterString):

item.setVisible(1)
else:
item.setVisible(0)
it += 1

If you don't like calling item.current() twice for some reason,
you could write this:

it = QListViewItemIterator(self.authListView)
item = it.current()
while item:
if item.text(0).contains(filterString) or \
item.text(1).contains(filterString) or \
item.text(2).contains(filterString):

item.setVisible(1)
else:
item.setVisible(0)
it += 1
item = it.current()

David
Jan 16 '07 #2
David Boddie wrote:
>
When it.current() returns None. You can rewrite what you already
have like this:

it = QListViewItemIterator(self.authListView)
while it.current():
item = it.current()
if item.text(0).contains(filterString) or \
item.text(1).contains(filterString) or \
item.text(2).contains(filterString):

item.setVisible(1)
else:
item.setVisible(0)
it += 1

If you don't like calling item.current() twice for some reason,
you could write this:

it = QListViewItemIterator(self.authListView)
item = it.current()
while item:
if item.text(0).contains(filterString) or \
item.text(1).contains(filterString) or \
item.text(2).contains(filterString):

item.setVisible(1)
else:
item.setVisible(0)
it += 1
item = it.current()

David
Ah, of course!
Thanks!!

Tina
Jan 17 '07 #3

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

Similar topics

10
by: Ilya Knizhnik | last post by:
Dear All, I am fairly new to Python. I have found it an easy language to learn and a very usefull one for many tasks. Currently I am working on...
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...
8
by: simo | last post by:
OK, so I'm at the stage where I want to make a choice between wxPython and PyQt. Currently I'm using wxPython mainly due to the fact that it has...
5
by: Bob Parnes | last post by:
I cannot find a reference on identifying multiple selections in QListView. Apparently one has to iterate through all the items and test each...
10
by: svenn.are | last post by:
Hi, I wanted to run a program that is written in PyQt on my mac, and went over to Riverbank to get PyQ 3.13 and SIP 4.1.1 sources. I followed...
3
by: Fabio | last post by:
Hi all, I'm about to write an application, and I'd like to use PyQt, but before choosing this toolkit I would like to clarify some particular...
10
by: Simon John | last post by:
After quite a while of wxPython I'm getting back into PyQt, mainly due to the announcement by Trolltech that they will make a GPL version of Qt4...
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...
3
by: Phil Thompson | last post by:
Riverbank Computing is pleased to announce the release of PyQt v4.0beta1 available from http://www.riverbankcomputing.co.uk/pyqt/. PyQt is a...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.