This project is a python PySide6 port of https://github.com/oKcerG/SortFilterProxyModel; a QSortFilterProxyModel exposed to QML written by oKcerG.
Please refer to oKcerG's documentation for usage as much of this implementation is based on oKcerG's implementation.
Note: the version of the qml exposed SortFilterProxyModel
is 0.2
to match that of oKcerG's project so that existing .qml code from your projects can be re-used quickly.
ProxyRoles
QQmlSortFilterProxyModel::componentCompleted
. In PySide6, there is noQ_INTERFACES
macro enabling a class to inherits fromQSortFilterProxyModel
andQQmlParserStatus
. Hence inheriting fromQQmlParserStatus
doesn't cause errors, however thecomponentCompleted
method is not called.- Some of the sorters are not yet ported
- The
delay
functionality is not ported - Attached properties not ported
Because attached properties are not ported, there is a difference in using the AnyOf
and AllOf
filters:
// oKcerG's
AnyOf {
RoleFilter {...}
RegExpFilter {...}
//...
}
// python implementation
AnyOf {
// need to assign a list of Filter to the filters property
filters: [
RoleFilter {...},
RegExpFilter {...},
//...
]
}
- download /clone the repostitory
- copy
src/qmlsortfilterproxymodel
to your project - import and register the
SortFilterProxyModel
toqml
# main.py
import qmlsortfilterproxymodel
# register qml types before QQmlApplicationEngine.load("main.qml") is called
qmlsortfilterproxymodel.registerQmlTypes()
- Instantiate
SortFilterProxyModel
inqml
// SomeFile.qml
import SortFilterProxyModel 0.2
SortFilterProxyModel {
//...
}
- Create a virtual environment (currently
venv
folder is under.gitignore
) and activatepython3 -m venv venv
source venv/bin/activate
- Install requirements (
PySide6
)pip3 install -r requirements.txt
- Run the example project
python3 example/main.py
Once the example window launches, you can use the TextField
to filter by name.