Qt QTreeWidget 保留排序
如何在 Qt QTreeWidget 中实现保留排序?即我希望尽可能保留树的先前顺序。这允许用户执行诸如单击“名称”列标题,然后单击“日期”列标题之类的操作,生成的树将按日期显示 QTreeWidget 中的项目,然后按名称显示。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,你不能。 QTreeWidget 使用不可访问的(和内部的)
QTreeModel
作为其操作,包括排序。通常,为此,您需要在
QAbstractItemModel< 中实现稳定排序 /代码> 子类。稳定排序会将位置不需要更改的项目保留在同一位置。
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.