I have QTreeWidget based class and need to do sorting by Qt::UserRole. How can I do this ? I know that QStandartItemModel has such method and treeWidget has model() method which return model, but it's QAbstractItemModel type which has no setSortRole method.
Yes, but I use QTreeWidget, non view and setModel is private method in QTreeWidget. So I can't do this: @QSortFilterProxyModel sortModel;
sortModel.setSourceModel(model());
setModel(&sortModel);@
Ah, yes, right.
I'd suggest to move away from QTreeWidget towards using QTreeView then :-) The API for QStandardItemModel is quite similar to the API of QTreeWidget for items, so the changes to your code should be minimal.