QTableView sort signal?

I use QTableView + QStandardItemModel to display some data (data stored in some other data structure), and this table view is sortable.

Since it is sorted, when sorting this model I also need to sort the order of the stored data. I am trying to implement a slot for a sorting signal, but I do not know which signal is emitted when I click on the header to start the sorting action.

I tried a click, but it was emitted only for a data row, not for headerData. what should I do if I want to do something else when sorting QtableView + QStandardItemModel?

+5
c ++ qt qt4 qtableview qabstractitemmodel
source share
2 answers

View title can be obtained using

QHeaderView * QTableView::horizontalHeader () const

Now with the received QHeaderView you can connect the slot to the signal,

 void QHeaderView::sectionClicked ( int logicalIndex ) [signal]. 

From the Qt 4.5 documentation. This signal is emitted when a section is clicked. The logical index of a partition is determined by the logical index. Note that a section signal will also be emitted.

Hope this helps.

+6
source share

There is a sortIndicatorChanged(int, Qt::SortOrder) signal in the header above, so it could be wiser to use

In addition, you can look at QSortFilterProxyModel for more details here http://doc.qt.io/qt-4.8/qsortfilterproxymodel.html#details

+1
source share

All Articles