In Qt docs http://doc.qt.io/qt-5/model-view-programming.html#model-subclassing-reference , it's said that, If your model is sortable, ie, if it reimplements the QAbstractItemModel::sort()
function, both QTableView
and QTreeView
provide an API that allows you to sort your model data programmatically. In addition, you can enable interactive sorting (ie allowing the users to sort the data by clicking the view's headers), by connecting the QHeaderView::sortIndicatorChanged() signal
to the QTableView::sortByColumn() slot
or the QTreeView::sortByColumn() slot
, respectively. However, the QTreeView::sortByColumn()
is not a slot in QTreeView
in Qt 5.4. Is there any thing wrong?The source code in Src/qtbase/src/widgets/itemviews/qtreeview.h shows that.
QTreeView::sortByColumn
wasn't a slot before: http://qt-project.org/doc/qt-4.8-snapshot/qtreeview.html#sortByColumn
And QTreeView::sortByColumn
isn't a slot now: http://doc.qt.io/qt-5/qtreeview.html#sortByColumn
There is nothing "wrong" with this implementation. The behavior of Qt 5 QTreeView will work exactly like a Qt 4 QTreeView with respect to sortByColumn
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.