views:

200

answers:

1

Hi all,

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?

A: 

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.

Adam W
Thanks Adam. I wrote it myself.I'm slightly realizing that I had to change to the Model/View framework at some stage anyway, so I guess now is the time. Thanks.
Magus