这是一个后续问题
this one
已经修好了。
我的模型有一些自定义函数,它们在树状视图中被调用。例如,我的
ItemModel
班级:
class ItemModel : public QAbstractItemModel
{
// ...
Q_INVOKABLE void addExpandedItem(const QModelIndex &index);
Q_INVOKABLE void removeExpandedItem(const QModelIndex &index);
}
使用
项目模型
类别as
sceneModel
ParentClass
:
class ParentClass : public QObject
{
Q_OBJECT
Q_PROPERTY(ItemModel * sceneModel READ sceneModel CONSTANT)
private:
ItemModel *m_sceneModel;
}
打电话
/
这些自定义功能包括:
TreeView {
model: parentClass.sceneModel
selection: ItemSelectionModel {
model: parentClass.sceneModel
}
onExpanded: {
model.addExpandedItem(index) // Calling custom function
}
onCollapsed: {
model.removeExpandedItem(index) // Calling custom function
}
}
我现在打算用我的模型过滤
QSortFilterProxyModel
如中所述
original question
QSortFilterProxyModel
代理模型。我收到这样的错误:
qrc:/.../...Tree.qml:191: TypeError: Property 'addExpandedItem' of object QSortFilterProxyModel(0x1f197c082c0) is not a function
因此,我想知道如何通过
QSortFilterProxyModel