Search code examples
c++qtqmlmodel-view

QML TreeView display nodes by levels or custom delegate


I have a tree model derived from a QAbstractItemModel. And I can display the data in a tree like way.

enter image description here

What I want is to display teh data by the layers. To display only one level of a layer at a time AND put each layer on a stack and navigate backwards by poping the layer from the stack. enter image description here

I guess I have to implement a custom delegate? Any advice would be highly appreciated. Thank you.


Solution

  • To to do it completely by guides we should use DelegateModel and DelegateModel.rootIndex

       DelegateModel {
            id: delegateSupportPropConfigModel
    
            model: supportModel
    
            delegate: SupportPropConfigListItem {
                id: currentItem
                width: scrollRect2.width - 60
                fieldName: model.fieldName
                fieldValue: model.value 
    
                onClick:{
                  delegateSupportPropConfigModel.rootIndex = supportPropConfigModel.index(0, 0, supportPropConfigModel)
                }
            }
        }
    
        Column {
            id: columnSettings
            spacing: 2
    
            Repeater {
                model: delegateSupportPropConfigModel
            }
        }