[PyQt] QTreeView and sorting

Hans Meine meine at informatik.uni-hamburg.de
Thu Nov 18 14:38:53 GMT 2010


Op den Middeweken 17 November 2010 Klock 17:42:20 hett dizou schreven:
> I am using a QTreeView and I have sorting enabled. Sorting works great, but
> I want one column to be sorted a specific way that isn't how Qt does it by
> default. I took a look at QSortFilterProxyModel, but this class looks more
> like a way to sort and filter data before the data is displayed in the
> treeview. I am looking to sort the data a specific way after the data is
> already in the tree view and after the user requests it to be sorted that
> way. How would I do this?

QAbstractItemModel has a sort method, but I was looking for the same thing 
today, and found something better: sortRole().  Given this, you can simply let 
data() return a modified column just for sorting.

HTH,
  Hans


More information about the PyQt mailing list