[PyKDE] Custom sorting function for the QListView widget

Fernando Jorge Silveira Filho fernando at land.ufrj.br
Sat Jul 3 21:58:00 BST 2004


Hi folks,

I have been programming Qt for a while now, but recently I started using 
PyQt and now I ran into a problem.

I am developing a very simple application that show lots of results from 
a SQL query onto a QListView. I have chosen doing this on Python since 
it is such a simple task, but now I want to be able to customize the 
sorting function used when the user clicks a column tab.

Namely I have numeric data in some columns and I need these to be 
properly sorted (QListView's default sorting function just performs 
string comparision). I have tried subclassing QListViewItem from my 
Python script and reimplementing the proper method ("compare( )", I 
guess) and it worked; numbers could be sorted as numbers in this new 
Widget. However sorting through this is AWFULLY SLOW for my application.

It seems clear to me that there is a performance loss caused by the fact 
that the compare() method (which is obviously a bottleneck for the 
sorting routine) is now in the script instead of the binary Qt library.

Since customized sorting for ListViews seems like such a common task for 
me, I am wondering whether I did something wrong, or if there is another 
way of doing this within PyQt.

Thanks in advance,
Fernando




More information about the PyQt mailing list