Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically sort a QTreeWidget column?

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.

like image 833
Emilio Avatar asked Dec 16 '08 19:12

Emilio


1 Answers

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.

like image 74
Bille Avatar answered Nov 03 '22 12:11

Bille