FunctionFilter QML Type

Filters data in a SortFilterProxyModel based on the evaluation of the designated 'filter' method. More...

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

Filter

Status: Preliminary

This type is under development and is subject to change.

Detailed Description

FunctionFilter allows user to define the designated 'filter' method and it will be evaluated to filter the data. The 'filter' method takes one argument and it can be defined as inline component as below:

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)
            }
        }
    ]
}

Note: The user needs to explicitly invoke SortFilterProxyModel::invalidate whenever any external qml property used within the designated 'filter' method changes. This behaviour is subject to change in the future, like implicit invalidation and thus the user doesn't need to explicitly invoke 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.