4

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.

hauron
  • 4,550
  • 5
  • 35
  • 52
  • How do you know which node to display? What is the criterion? – vahancho Nov 12 '13 at 13:17
  • Display only nodes with no child nodes (e.g. *node->isLeaf() == true* or *node->childCount() == 0*), so I guess it could be broadened up to "display a *list* of only the nodes of the tree, which meet an arbitrary condition". – hauron Nov 12 '13 at 13:54
  • 1
    Maybe solution for this problem in this article: http://stackoverflow.com/questions/37588408/how-to-display-sub-rows-of-qabstractitemmodel-in-qtableview?lq=1 – Kirill Chernikov Jun 05 '16 at 13:20

0 Answers0