“group by” proxy model

不打扰是莪最后的温柔 提交于 2019-12-05 22:05:08

Depending on what you want as a final result :

  • you can achieve the filtering without having to implement QAbstractProxyModel.

    The QSortFilterProxyModel can sort by Item role , default being Qt::DisplayRole. But if you put your group property in a custom Role of your item, then you can sort by this custom role : cf : https://doc.qt.io/qt-5/qsortfilterproxymodel.html#sortRole-prop

    That should do the main job of sorting for the specific view ordered by Group.

    But you won't have "collapsable group" node. hard to say if you can manage to equivalent feature with a custom renderer.

  • Otherwise, the hard way, as suggested by Felix, implement your custom QAbstractProxyModel that will create node group indexes.

  • Last solution : create your own (base) model (something like MyTree and Map<Group,Node> , and two Qt models (one for each view)). Update both models via Qt's signal/slot mecanism when your base model is updated and vice versa.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!