[PyQt] QStandardItemModel sort bug

Matt Chambers chambers at imageworks.com
Thu Jun 7 23:32:55 BST 2007


Hey all, I'm having this problem with QStandardItemModel, its killing 
me.  Basically, when I sort the QtreeView by a column, it loses the 
selection highlight column 0.  The column 0 highlight actually moves to 
another row.  It seems to move to the row that was in the selected rows 
spot before the model was sorted.  This only happens when I sort the 
parent children different ways using sort children.

This is what I override the model's sort method with:

 def sort(self,col,way):
       
        self.__sortCol = col
        self.__sortWay = way
       
        
self.invisibleRootItem().sortChildren(Row.PRI,QtCore.Qt.DescendingOrder)
        for row in range(0,self.invisibleRootItem().rowCount()):
            parent =  self.invisibleRootItem().child(row,0)
            if parent.hasChildren():
                parent.sortChildren(self.__sortCol,self.__sortWay)

So, I want the children of the root item be always be sorted a 
particular way and for the sort buttons to effect only the children.

Any help would be appreciated.  I think this might be a QT issue though.

Matt







More information about the PyQt mailing list