FunctionSorter QML Type

根据指定 "排序 "方法的评估结果对SortFilterProxyModel 中的数据进行排序。更多

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

Sorter

Status: Preliminary

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

详细说明

FunctionSorter 允许用户定义指定的 "排序 "方法,并通过评估该方法对数据进行排序。该方法需要两个指定参数类型的参数(lhs 和 rhs),数据可按如下方式访问以进行评估、

SortFilterProxyModel {
    model: sourceModel
    sorters: [
        FunctionSorter {
            id: functionSorter
            component RoleData: QtObject {
                property real age
            }
            function sort(lhsData: RoleData, rhsData: RoleData) : int {
                return (lhsData.age < rhsData.age) ? -1 : ((lhsData === rhsData.age) ? 0 : 1)
            }
        }
    ]
}

注意: 每当指定 "排序 "方法中使用的任何外部 qml 属性发生变化时,用户都需要明确调用SortFilterProxyModel::invalidateSorter 。这种行为将来会发生变化,就像隐式失效一样,因此用户不需要显式调用SortFilterProxyModel::invalidateSorter

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