Results 1 to 2 of 2

Thread: QRegExp not (!) can you filter based on QRegExp not be matched?

  1. #1
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QRegExp not (!) can you filter based on QRegExp not be matched?

    Qt Code:
    1. m_UserModelProxy = new UserModelProxy(this);
    2. m_UserModelProxy->setSourceModel(this);
    3. m_UserModelProxy->setDynamicSortFilter(true);
    4. m_UserModelProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
    5.  
    6. m_UserModelProxy->setFilterRole(UsersModel::IDRole);
    7. QRegExp filter("ametinc");
    8. m_UserModelProxy->setFilterRegExp(filter); //I want to filter out ametinc from the model but it filters everything else is there a way to QRegExp is not equal to ametinc ....
    To copy to clipboard, switch view to plain text mode 

    this may not be the correct way to achieve this however I figured if I could filter out the one item form the model I don’t want to display I figured I try proxyModel


    I'm still having a little trouble filtering out the ametinc user, I can set a proxy filter to filter out everything else besides ametinc cause thats what the filter is set to, I'm not sure how to get it to remove or hide it form the model though here is some code I been thinking about

    the RegExp its filtering what to display I want to filter what not to display if that makes sense

    Qt Code:
    1. m_UserModelProxy = new UserModelProxy(this);
    2. m_UserModelProxy->setSourceModel(this);
    3. m_UserModelProxy->setDynamicSortFilter(true);
    4. m_UserModelProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
    5.  
    6. m_UserModelProxy->setFilterRole(UsersModel::IDRole);
    7. QRegularExpression filter("ametinc");
    8. if(filter.hasMatch()){
    9. removeUser(filter.index);
    10. }
    11. m_UserModelProxy->setFilterRegExp(filter);
    12.  
    13. //m_UserModelProxy->setFilterRegExp(QRegExp::operator !=(filter));
    14. //m_UserModelProxy->invalidate();
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 7th March 2017 at 00:35.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QRegExp not (!) can you filter based on QRegExp not be matched?

    Use a custom QSortFilterProxyModel and implement
    Qt Code:
    1. virtual bool filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const
    2. virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QRegExp help
    By bandito in forum Qt Programming
    Replies: 4
    Last Post: 2nd May 2016, 19:35
  2. Can't get the QRegExp I need
    By roseicollis in forum Newbie
    Replies: 5
    Last Post: 30th March 2015, 20:41
  3. Help on QRegExp
    By dmr in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2012, 16:03
  4. QRegExp parsing matched quoted strings
    By jhndnn in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 00:05
  5. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 01:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.