简体   繁体   English

Qt Treewidget对顶级项目进行排序

[英]Qt treewidget sorting top-level items

I am having a difficult time overloading QTreeWidgetItem 's < operator. 我在重载QTreeWidgetItem<运算符时遇到困难。

I have a list of QTreeWidgetItems , some top-level items and some children. 我有一个QTreeWidgetItems列表,一些顶级项目和一些孩子。 When the user activates the "date created" column to sort the tree, the sort occurs at the child level. 当用户激活“创建日期”列以对树进行排序时,排序发生在子级。

In other words, imagine a tree like this: 换句话说,想象这样一棵树:

Item A - latest modification 9/24/12
  3rd Modified -             9/21/12
  2nd Modified -             9/15/12
  1st Modified -             9/10/12

Item B - latest modification 9/23/12
  2nd Modified -             9/23/12
  1st Modified -             9/22/12

When the date column is activated to sort ascending, I would expect the return result to be: Item A, then Item B... but instead, the sort occurs on the 1st modified date of the item. 当日期列被激活以升序排序时,我希望返回结果为:项目A,然后项目B ...,但是排序发生在项目的第1个修改日期。 I am returned with Item B then Item A. Even though none of the top-level items are expanded, or active. 我返回了项目B和项目A。即使没有一个顶级项目被展开或激活,也没有。

If you use a QWidgetTree to dispay your QTreeWidgetItems list : You can add your 2 firsts level item (item A and B), sort your QwidgetTree and then add your low level items. 如果您使用QWidgetTree来支付QTreeWidgetItems列表:您可以添加两个第一级项目(项目A和B),对QwidgetTree进行排序,然后添加低级项目。 so your tree will be sorted by latest modification 这样您的树将按照最新的修改进行排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM