QTableView to display only leaves of a tree model implemented with QAbstractItemModel

拥有回忆 提交于 2019-12-10 20:58:18

问题


Assume I have a tree structure (tree leaves in bold, sorry for the dots):


  • A
    • A1
    • A2
  • B
    • B1
      • B11
    • B2
  • C

stored in a QAbstractItemModel (with set parent/child relations).

How to display only the tree leaves in a QTableView?

Basic idea was to implement a QSortFilterProxyModel. Intuition suggested there would be a way to iterate through the tree and return a valid index if the item is a leaf, or QModelIndex() if not.

// QAbstractItemModel *model;
m_leavesModel.setSourceModel(model); // QSortFilterProxyModel m_leavesModel;
m_leavesTableView->setModel(&m_leavesModel);

At the moment I can only display "first level" items - A, B and C, just below the root.

来源:https://stackoverflow.com/questions/19927952/qtableview-to-display-only-leaves-of-a-tree-model-implemented-with-qabstractitem

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