I\'m using a QML PathView to show my model. Such a model inherits from QStandardItemModel and has two levels of data (parent items and child items). I need to s
QML works with list models, as you have seen also in your case. However, this limitation can be easily overcome by using DelegateModel. Quoting the documentation:
It is usually not necessary to create a DelegateModel. However, it can be useful for manipulating and accessing the modelIndex when a QAbstractItemModel subclass is used as the model. Also, DelegateModel is used together with Package to provide delegates to multiple views, and with DelegateModelGroup to sort and filter delegate items.
Such QML type has a property rootIndex. Quoting again the documentation:
QAbstractItemModel provides a hierarchical tree of data, whereas QML only operates on list data. rootIndex allows the children of any node in a QAbstractItemModel to be provided by this model.
This is the property you need to set (and reset), as described in the example of the linked documentation. Note that by using DelegateModel the delegate in your PathView should not be defined. A working example (visualdatamodel/slideshow.qml) is available in the standard framework distribution under the path:
Qt/QtXXX/Examples/Qt-5.4/quick/views
Finally note that DelegateModel and VisualDataModel are often used in an interchangeable way since
This type (VisualDataModel) is provided by the Qt QML module due to compatibility reasons. The same implementation is now primarily available as DelegateModel in the Qt QML Models module.