Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSortFilterProxyModel filter whole word.
Forum Updated to NodeBB v4.3 + New Features

QSortFilterProxyModel filter whole word.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    For my tableView I am using a QSortFilterModel to which a QRegExp is set

    @QRegExp exp;
    if (isWholeWord) // checkbox for whole words
    exp.setPattern(QString("^%1$").arg(text));
    else
    exp.setPattern(text);

    exp.setPatternSyntax(QRegExp::FixedString);
    
    exp.setCaseSensitivity(isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
    
    m_proxyModel->setFilterRegExp(exp);@
    

    As per the documentation of "QRegExp":http://qt-project.org/doc/qt-5.0/qtcore/qregexp.html it should work , i tried with exp.indexIn(text) and it return 0 but the model does not show anything.

    what am I missing ?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      since you set the pattern syntax to QRegExp::FixedString it actually tries to find "^bla$".
      I think you only want this for your else-case.

      --- 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
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Thank you, works perfect !!!

        Regards
        Sam

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          Hi,

          The above implementation worked very well, Since I am using the filterModel on my tableView the regExp is set for the whole cell, this mean if the filter text is "abc" and isWholeWord is true then its filters all the rows that has exact "abc" set for the complete cell.

          What I want is it should check if the cell contains the filter text

          Eg: Filter Text : Dubai isWholeWord: true

          Dubai
          Dubai Uae
          Hello Dubai

          All the rows should be visible that contains Dubai as whole word, how to do that?

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            if i understood you correct, then just leave out the line
            @
            exp.setPatternSyntax(QRegExp::FixedString);
            @

            --- 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
            0

            • Login

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