开发者

stable sorting QTreeWidgetItems in QTreeWidget?

开发者 https://www.devze.com 2022-12-20 16:45 出处:网络
I have a list of QTreeWidgetItems (with children) in a QTreeWidget. I do not use a model for my data.

I have a list of QTreeWidgetItems (with children) in a QTreeWidget. I do not use a model for my data.

From another window in my application the user can navigate thru the same set of data (viewed differently) and the QTreeWidget in the first window then highlights that specific row by setting the background colour.

However, when the QTreeWidget is sorted on a column wher开发者_JAVA百科e some of the items have the same value it is undefined which item is first. When I then navigate using the other window and the background colour of the item is set, the equal items swaps place in the view automatically. This looks very strange.

I suspect this is due to the sorting algorithm of QTreeWidget, but does anyone know a possible workaround to this?


Are you using QItemSelectionModel to do this, or did you write it yourself?

  • If you wrote it yourself I would suggest using QItemSelectionModel.
  • If you didn't, it sounds like you want a custom sorting algorithm which would require creating a derived QTreeWidget, if you are doing that, you might as well just use QTreeView and a custom QAbstractItemModel.

Also, if you have two views of the same data, I would HIGHLY recommended using the Model/View framework and a QTreeView.

0

精彩评论

暂无评论...
验证码 换一张
取 消