I have a QTreeWidget that I insert items in, and the user can select a column to sort it. As the items are being inserted, they just get appended to the end instead of having the sort being done automatically. If I click the header to switch between ascending/descending it will sort the current items.
I figured I could call sortItems() and use the column that is returned from sortColumn(), but I am unable to see how I can see if the user is doing an ascending or descending sort.
I’m not worried about the efficiency of this, so I don’t want to wait until the insertions are done and then do the sort. I’d like a real-time sorted list.
Thanks!
If your tree widget is called treeWidget, you should be able to call the header() method, which is from QTreeWidget’s parent QTreeView, then sortIndicatorOrder() from the QHeaderView class:
With this, you know the user’s current sort order, and you can apply your sort on insert according to this.