[PySide] problem with custom sorting in QSortFilterProxyModel

Frank Rueter | OHUfx frank at ohufx.com
Tue Jun 26 09:32:32 CEST 2012


Hi all,

I'm trying to implement a custom sort behaviour on my first model/view 
structure and am hitting a road block (undoubtedly human error).
My model is just a list of dictionaries all living in column 0 of their 
respective rows. I am not splitting up the dictionaries' keys into their 
own columns as I need to draw each one as a single custom 
widget/delegate eventually (maybe this is possible anyway??).

The sorting code in my proxy model code like like this:

     def sortBy( self, attr ):
         self.__sortBy = attr
         self.sort( 0, Qt.AscendingOrder ) # THIS DOES NOT GET CALLED 
WHEN THE COMBO BOX CHANGES A SECOND TIME

     def lessThan( self, left, right ):
         '''Custom sorting behaviour'''
         leftTool = ( self.sourceModel().itemFromIndex( left ) )
         rightTool = ( self.sourceModel().itemFromIndex( right ) )
         leftData = leftTool.data()[ self.__sortBy ]
         rightData = rightTool.data()[ self.__sortBy ]
         return leftData < rightData


As the comment in the code says, the first time I call sort() it works 
fine, but subsequent calls do nothing. It's like nothing exists in 
column 0 anymore after things were sorted once?!

I'm sure I'm missing something very obvious here.

Here is the entire test code:
http://pastebin.com/iuqXbdtm

I'm not sure if I'm even going about this in the right way so any help 
would be greatly appreciated as usual.

Cheers,
frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120626/0bb9d9c0/attachment.html>


More information about the PySide mailing list