2

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 where 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?

4

1 回答 1

1

你是QItemSelectionModel这样写的,还是你自己写的?

  • 如果你自己写,我建议使用QItemSelectionModel.
  • 如果你没有,听起来你想要一个自定义排序算法,这需要创建一个 derived QTreeWidget,如果你这样做,你不妨只使用QTreeView和一个 custom QAbstractItemModel

此外,如果您有相同数据的两个视图,我强烈建议您使用模型/视图框架和QTreeView.

于 2010-02-17T17:44:39.360 回答