In which column the data is sorted, QTableWidget

How to get some value that indicates in which column the data is sorted by (and increasing or decreasing) in a QTableWidget ? I could not find anything in the documentation about this, only about software programming.

+4
source share
1 answer

You can access this through the table header. Basically, in Qt, everything related to whole columns is access through the horizontal heading of the table, and everything related to whole rows is available, albeit with vertical headers. This includes default sizes, stretching, or, in your case, sorting properties.

Function

SortIndicatorOrder() returns the sort order as Qt::SortOrder enum wihch can be either Qt::AscendingOrder aka 0 or Qt::DescendingOrder aka 1 . You can use it ilke:

 ui.yourTable->horizontalHeader()->sortIndicatorOrder(); 
Function

sortIndicatorSection() returns a column according to wihch data. Column numbers start at 0. You can call it this way:

 ui.yourTable->horizontalHeader()->sortIndicatorSection(); 
+11
source

All Articles