Qt document 中有一个非常简单的树模型示例.我加了一行
view.setSortingEnabled(true);
在 main.cpp
中启用 TreeView 排序。当我运行它时,我会在标题中看到一个排序指示器。但是,无论我如何单击标题,项目都不会排序。有什么我忽略的吗?
最佳答案
使用QSortFilterProxyModel 以你的观点。
View 的 sortingEnabled
属性启用 View 中的排序按钮。然而,实际的排序需要在模型的 sort() 中实现。方法。
像这样使用 QSortFilterProxyModel:
QSortFilterProxyModel* pProxyModel = new QSortFilterProxyModel(pView);
pProxyModel->setSourceModel(pModel);
pView->setModel(pMdl);
pView->setSortingEnabled(true);
关于c++ - Qt 中的项目未在 TreeView 中排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15812521/