[Qt-qml] QSortFilterProxyModel with QML ListView
Cornelius Hald
hald at icandy.de
Tue Sep 14 17:25:17 CEST 2010
Hi,
I've now managed to use my own data model together with a customized
QSortFilterProxyModel to provide sorting and searching for my QML UI. I
still have two open questions, though.
1) Is there a way to animate sorting? I have animations for inserting
and removing data and they are also used when filtering (very nice). But
I would also like to give the user some feedback about changed sorting
as well.
2) In my proxy class I have to call beginResetModel() and
endResetModel() around my sorting code. Otherwise the QML ListView does
not update itself. Is this really needed? I thought the
QSortFilterProxyModel class would take care about that itself. Making
the filter work doesn't need these calls.
My code looks like this:
SortedModel::SortedModel(QObject *parent) :
QSortFilterProxyModel(parent)
{
}
void SortedModel::sortBy(QString roleName)
{
beginResetModel(); // Do I really need that?
if (roleName == "name") {
setSortRole(MyModel::NameRole);
} else if (roleName == "description") {
setSortRole(MyModel::DescriptionRole);
}
endResetModel();
}
void SortedModel::search(QString search)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
setFilterRole(MyModel::NameRole);
setFilterWildcard(search);
}
Thanks (again) :)
Conny
More information about the Qt-qml
mailing list