QTableView, QAbstractTableModel, QSortFilterProxyModel, Sorting
-
Code from Qt doc:
void QTableView::sortByColumn(int column, Qt::SortOrder order) { Q_D(QTableView); if (column < 0) return; // If sorting is enabled it will emit a signal connected to // _q_sortIndicatorChanged, which then actually sorts d->horizontalHeader->setSortIndicator(column, order); // If sorting is not enabled, force to sort now if (!d->sortingEnabled) d->model->sort(column, order); // this sort function is called from //QAbstractItemModel so do nothing. See hereunder function }
/*! Sorts the model by \a column in the given \a order. The base class implementation does nothing. */ void QAbstractItemModel::sort(int column, Qt::SortOrder order) { Q_UNUSED(column); Q_UNUSED(order); // do nothing }
In Qt doc:
-
QTableView::setSortingEnabled(true) calls void QTableView::sortByColumn(int column, Qt::SortOrder order)
-
QTableView::sortByColumn fuction If sorting is enabled it will emit a signal connected to
_q_sortIndicatorChanged, which then actually sorts or If sorting is not enabled, force to sort now but if only the sort function in QAbstractItemModel::sort is overloaded and the body of the function has a code which sort, or you have customized QSortFilterProxyModel which has the sort function and the function is called when you click the header column arrow but not sorts when you setData from tableView level. -
if QTableView::setSortingEnabled(false) the header column arrow for descending or ascending sorting is not seen so there is no posibility to sort from the level of TableView.
-