Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Hide/show ListView sections dynamically



  • Hi,

    I have a ListView that has a ListView as delegate.
    The Items of the child ListView are elements of a given category. Then, the items of the parent listView are the different categories.
    The model for the children lists are a custom of QSortFilterProxyModel. Then, I would like that if, for filtering options, a child list does not have elements to show, hide the category title. Now, with current behavior, category header is shown with no children.
    Code is:

    ListView {
    			id: headers
    			anchors.fill: parent
    			clip: true
    			boundsBehavior: Flickable.StopAtBounds
    
    			model: _headersModel
    
    			delegate: 
    				Item {
    					width: parent.width
    					height: some_value
    
    					ListView {
    						id: items_of_same_category
    						anchors.fill: parent
    						spacing: 5
    						clip: true
    						interactive: false
    
    						model: proxy_model
    
    						delegate: component_delegate
    					}
    				}
    
    			section.property: "category_value"
                            section.criteria: ViewSection.FullString
                            section.delegate: header_delegate
                            section.labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart            
    		}
    

    In case of "proxy_model" is retrieving 0 children, header should not be visible.



  • Hey @Adso4. You can use this excellent library that saves a lot of work.

    https://github.com/oKcerG/SortFilterProxyModel

    Good luck.


Log in to reply