本页内容

AllOfFilter QML Type

在“SortFilterProxyModel ”中,使用逻辑“AND”将多个筛选条件组合在一起。更多内容...

Import Statement: import QtQml.Models
Since: Qt 6.12
Inherits:

FilterBase

Status: Technology preview

此类型处于技术预览阶段,内容可能会有变动。

属性

详细说明

AllOfFilter 将一组子筛选器进行分组,仅当所有子筛选器均接受某行或某列时,才会将其识别为匹配项。这相当于直接将多个筛选器应用于 `SortFilterProxyModel`,但允许将该组作为一个整体进行启用、禁用或反转。

以下代码片段演示了如何使用 AllOfFilter,仅筛选出同时满足以下条件的行:status 为"active" 且favorite 为true :

SortFilterProxyModel {
    sourceModel: model
    filters: [
        AllOfFilter {
            ValueFilter {
                roleName: "parent";
                value: "root"
            }
            ValueFilter {
                roleName: "status";
                value: "active"
            }
        }
    ]
}

属性文档

filters : list<FilterBase>

使用逻辑“与”运算进行评估的子过滤器列表。如果该列表中的所有过滤器均通过该行,则该行被接受。

这是默认属性,因此无需使用filters 关键字即可将过滤器声明为直接子元素:

AllOfFilter {
    ValueFilter { roleName: "status"; value: "active" }
    ValueFilter { roleName: "parent"; value: "root" }
}

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.