ListModel with multiple filters
-
I am using QAbstractListModel and Listview in my application. I want to filter the listview content by using multiple keys. User will input the keys using which he/she wants to filter (Each word is a filter key and if any of keys are found in the listelement only then it should be shown). I have looked into QSortFilterProxyModel, which can support only one filter string. Is there any way to filter with multiple keys?
-
I am using QAbstractListModel and Listview in my application. I want to filter the listview content by using multiple keys. User will input the keys using which he/she wants to filter (Each word is a filter key and if any of keys are found in the listelement only then it should be shown). I have looked into QSortFilterProxyModel, which can support only one filter string. Is there any way to filter with multiple keys?
@Yaswanth said in ListModel with multiple filters:
I have looked into QSortFilterProxyModel, which can support only one filter string. Is there any way to filter with multiple keys?
since it supports regular expressions as filters you can for example concatenate a string list and do the filtering.
QStringList filters; QString rx; for( int i = 0; i < filters.count(); ++i ) { QString filter = QRegExp::escape( filters.at(i) ); if( i > 0 ) rx += '|'; rx += filter; } filterModel->setFilterRegExp( QRegExp(rx) );
-
Can't you do that with a single regexp pattern ?
bonjour|hello
will match on either "bonjour" or "hello" -
Can't you do that with a single regexp pattern ?
bonjour|hello
will match on either "bonjour" or "hello"@GrecKo
thats what i did?! -
@GrecKo
thats what i did?!@raven-worx Indeed, for some reason I didn't really read your answer and assumed you were reimplementing
filterAcceptRow()
in c++.OP asked for a QML answer so I only quickly glanced over yours, sorry :)