Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListModel with multiple filters

ListModel with multiple filters

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yaswanth
    wrote on last edited by Yaswanth
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • Y Yaswanth

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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) );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        Can't you do that with a single regexp pattern ?

        bonjour|hello will match on either "bonjour" or "hello"

        raven-worxR 1 Reply Last reply
        0
        • GrecKoG GrecKo

          Can't you do that with a single regexp pattern ?

          bonjour|hello will match on either "bonjour" or "hello"

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @GrecKo
          thats what i did?!

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          GrecKoG 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @GrecKo
            thats what i did?!

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            @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 :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved