Results 1 to 10 of 10

Thread: Search in tableView with 2 arguments

  1. #1
    Join Date
    Jul 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Search in tableView with 2 arguments

    Hello,
    I want to make a search with 2 arguments in tableView with regExp,
    here's the code:
    Qt Code:
    1. QString search = QInputDialog::getText(this,"Search","Enter search keyword",QLineEdit::Normal);
    2. proxyModel->setSourceModel(model);
    3. proxyModel->setFilterRegExp(QRegExp(search, Qt::CaseInsensitive, QRegExp::FixedString));
    4. proxyModel->setFilterKeyColumn(-1);
    5. ui->tableView->setModel(proxyModel);
    6. ui->tableView->show();
    To copy to clipboard, switch view to plain text mode 
    I want to search for Name and Surname matching exactly the correct row. How do i do that?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Search in tableView with 2 arguments

    Subclass the proxy model and reimplement filterAcceptsRow().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Search in tableView with 2 arguments

    @wysota
    I'm sorry can you show an example

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Search in tableView with 2 arguments

    Quote Originally Posted by alexandrius View Post
    @wysota
    I'm sorry can you show an example
    Docs for QSortFilterProxyModel contain an example of a custom filterAcceptsRow() method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Search in tableView with 2 arguments

    Quote Originally Posted by wysota View Post
    Docs for QSortFilterProxyModel contain an example of a custom filterAcceptsRow() method.
    Never understood anything from documentation. Please give me a practical example if you can

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Search in tableView with 2 arguments

    Quote Originally Posted by alexandrius View Post
    Never understood anything from documentation.
    Apparently there is something wrong with your reading skills.

    Please give me a practical example if you can
    Qt Code:
    1. bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
    2. const QModelIndex &sourceParent) const
    3. {
    4. QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
    5. QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
    6. QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
    7.  
    8. return (sourceModel()->data(index0).toString().contains(filterRegExp())
    9. || sourceModel()->data(index1).toString().contains(filterRegExp()))
    10. && dateInRange(sourceModel()->data(index2).toDate());
    11. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Search in tableView with 2 arguments

    I was too lazy for creating new class.
    So i used the old method for filtering.
    Then filtered already filtered model, that's it problem solved

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Search in tableView with 2 arguments

    You're probably right. Writing a subclass takes 10-15 minutes. "Solving" the problem "your way" -- 6 days. Good job.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Search in tableView with 2 arguments

    Quote Originally Posted by wysota View Post
    You're probably right. Writing a subclass takes 10-15 minutes. "Solving" the problem "your way" -- 6 days. Good job.
    First of all it takes maximum of 2 minutes. 2nd It doesn't mean i was 6 days fixing the problem, I'm rarely here. 3rd this way solves the problem very well. 4th you are a d1ck.
    I asked for life example not the documentation but you started joking about my reading skills, if you can't give an example do not do it and do not write that i can't read English. Not everyone knows Qt as well as you!

    you are a big pr1ck seriously.

    Sincerely Alex. I wish your d1ck will wither out
    Last edited by alexandrius; 22nd September 2013 at 19:43.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Search in tableView with 2 arguments

    Quote Originally Posted by alexandrius View Post
    I asked for life example not the documentation
    What's wrong with the example from the documentation? It does almost exactly what you wanted, except that in addition it checks the date.

    Thank you for you good wishes, I wish you all the best too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 14th November 2012, 21:00
  2. CustomContextMenu with arguments
    By toodles in forum Newbie
    Replies: 3
    Last Post: 27th June 2012, 13:25
  3. How to search on TableView ?
    By hohoanganh205 in forum Newbie
    Replies: 2
    Last Post: 5th January 2012, 11:27
  4. how to use arguments in Qt?
    By mr_kazoodle in forum Newbie
    Replies: 5
    Last Post: 26th January 2011, 20:04
  5. QVector arguments
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2007, 10:47

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
  •  
Qt is a trademark of The Qt Company.