How do you implement a preserve sort in a Qt QTreeWidget? I.e. I would like the previous order of the tree preserved as much as possible. This allows the user to do something like click the "Name" column header and then the "Date" column header, and the resulting tree shows the items in the QTreeWidget by Date and then by Name.
+3
A:
Unfortunately, you can't. QTreeWidget uses an inaccessible (and internal) QTreeModel
for its operations, including sorting.
Normally, to do so you would want to implement a stable sort within your QAbstractItemModel
subclass. A stable sort will leave items whose position doesn't need to change in the same location.
Kaleb Pederson
2010-02-03 23:13:21