筛选项目时动态隐藏QML ListView部分



我有一个ListView(父级(,它使用ListView(子级(作为委托,所以每个父级都是一些项的ListView。

举一个典型的例子,父列表可以是一个大小(L、M和S(的列表,每个子列表都是一个给定大小的动物列表(L只动物、M只动物、S只动物(。

这两个列表都使用从QAbstractListModel继承的自定义模型。但视图中使用的子列表模型是从QSortFilterProxyModel继承的自定义模型,具有过滤功能。

父列表中的项目作为子列表的"大小",因此它们被用作部分。视图显示为:

大型:-大型_小型_1-大_小_ 2

介质:-介质_最小_1-。。。

我需要的是,如果给定的部分在过滤后没有项目,则该部分必须不显示。在当前视图中,当过滤后没有"动物"时,会出现部分标题:

大型:

介质:-介质_最小_1-。。。

QML代码为:

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            
}

为什么不通过信号将cpp中的两个模型连接起来,只要没有第二个委托的项目,就从第一个模型中筛选出负责第二个模型中委托的项目。也就是说,如果没有Large_animal_*,请从第一个模型中筛选出Large值。

换句话说,尝试从cpp端解决您的问题,并让QML按照它应该做的那样显示模型

最新更新