本页内容

AnyOfFilter QML Type

在SortFilterProxyModel 中使用逻辑“或”运算组合多个筛选条件。更多内容...

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

FilterBase

Status: Technology preview

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

属性

详细说明

AnyOfFilter 将一组子过滤器进行分组,并为该组中至少一个子过滤器查找匹配的行或列。当您需要包含满足多个独立条件的行,且无需所有条件均需满足时,此功能非常有用。

以下代码片段演示了如何使用 AnyOfFilter 筛选满足以下任一条件的行:status 既为"active" 又为"pending" :

SortFilterProxyModel {
    sourceModel: model
    filters: [
        AnyOfFilter {
            ValueFilter {
                roleName: "status"
                value: "active"
            }
            ValueFilter {
                roleName: "status"
                value: "pending"
            }
        }
    ]
}

属性文档

filters : list<FilterBase>

使用逻辑“或”运算评估的子过滤器列表。如果该列表中至少有一个过滤器接受某行,则该行被接受。

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

AnyOfFilter {
    ValueFilter { roleName: "status"; value: "active" }
    ValueFilter { roleName: "status"; value: "pending" }
}

© 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.