Search code examples
c++qtqwidgetqtreeviewqabstractitemmodel

Can I use QAbstractListModel with QTreeView (hierarchy)?


Is it possible to use QAbstractListModel for a hierarchical QTreeView? I want to make very clear, that I am talking about a tree view with an expandable / collapsible hierarchy.

From the examples it seems not to be recommended, but is is possible (means stable + feasible)? The tutorial here shows an overview (at the bottom), which always uses QStandardItemModel for tree views.

I wonder what really makes the data appearing in a hierarchy? So far I can identify the following functions:

  1. data
  2. row count
  3. column count
  4. hasChildren

I wonder if it is possible to "fake" a hierarchy by applying the corresponding logic there. Or would this be a complete mess? Is there any example doing so (using QAbstractListModel for a hierarchy)


Solution

  • As pointed out by Retired Ninja:

    Straight from the documentation: Since the model provides a more specialized interface than QAbstractItemModel, it is not suitable for use with tree views;