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 h开发者_运维百科eader, and the resulting tree shows the items in the QTreeWidget by Date and then by Name.
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.
精彩评论