PyQt: QListviewItemIterator

Tina I tinaweb at bestemselv.com
Tue Jan 16 12:57:44 EST 2007


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



More information about the Python-list mailing list