FunctionFilter QML Type

根据指定 "过滤 "方法的评估结果过滤SortFilterProxyModel 中的数据。更多

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

Filter

Status: Preliminary

此类型正在开发中,可能会有更改。

详细说明

FunctionFilter 允许用户定义指定的 "过滤 "方法,并对其进行评估以过滤数据。filter "方法需要一个参数,可以定义为内联组件,如下所示:

SortFilterProxyModel {
    model: sourceModel
    filters: [
        FunctionFilter {
            id: functionFilter
            property int ageLimit: 20
            component RoleData: QtObject {
                property real age
            }
            function filter(data: RoleData) : bool {
                return (data.age <= ageLimit)
            }
        }
    ]
}

注意: 每当指定的 "过滤器 "方法中使用的任何外部 qml 属性发生变化时,用户需要明确调用SortFilterProxyModel::invalidate 。这种行为将来会发生变化,比如隐式失效,因此用户无需显式调用SortFilterProxyModel::invalidate

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