HI all,

just for future reference (if people have the same problem), the solution was to simply call self.invalidate() right before calling self.sort() in the proxy model.


Cheers,
frank


On 26/06/12 7:32 PM, Frank Rueter | OHUfx wrote:
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


_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside


_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to