How to display the search result on QListView?
-
Hello all.
I have such task, I want to search an item in model(QAbstractListModel) and display only the result of search on QListView,
How can I do it?thank you.
-
Hi,
AFAIK you can use "QSortFilterProxyModel":http://doc.qt.io/qt-5/qsortfilterproxymodel.html for this. Create a model based on QAbstractListModel and the use "setSourceModel":http://doc.qt.io/qt-5/qsortfilterproxymodel.html#setSourceModel to set this model as source to QSortFilterProxyModel. To filter out the items you can re-implement "filterAcceptsRow":http://doc.qt.io/qt-5/qsortfilterproxymodel.html#filterAcceptsRow and return true or false per the search criteria.