Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which column is data sorted by, QTableWidget

Tags:

c++

qt

qtableview

How to get some value which specifies which column the data is sorted by (and whether it's ascending or descending) in QTableWidget? I couldn't find anything in the documentation about it, only about sorting programmatically.

like image 773
tobi Avatar asked Aug 13 '12 11:08

tobi


1 Answers

You can access that through the table header. Basically in Qt everything that is related to whole columns is accesses through the horizontal header of the table, and everything related to whole rows is accessed though the vertical headers. This includes default sizes, stretches, or, in your case, the sort properties.

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

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

sortIndicatorSection() function returns the column by wihch data is sorted. Column numbers start with 0. You can call it like this:

ui.yourTable->horizontalHeader()->sortIndicatorSection();
like image 63
SingerOfTheFall Avatar answered Sep 16 '22 21:09

SingerOfTheFall