14

I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted.

Is there a way to force the automatic sorting in a specified column without calling .sortItems(column) at every item insertion?
If it's possible, I would highlight the whole sorted column.

ymoreau
  • 3,402
  • 1
  • 22
  • 60
Emilio
  • 3,901
  • 11
  • 44
  • 50
  • I don't see what difference (except for few lines of code) there is between manual and automatic sorting. Is there a reason why you can't do the sort upon item insertion? – Tuminoid Dec 17 '08 at 13:58

1 Answers1

16

To do this, use QTreeView::setSortingEnabled() and QTreeView::sortByColumn. Just remember to turn this on /after/ you initially populate the widget, and turn it off again /before/ doing any bulk updates for efficiency.

Romário
  • 1,664
  • 1
  • 20
  • 30
Bille
  • 321
  • 2
  • 4