Results 1 to 2 of 2

Thread: QSortFilterProxyModel search and view scroll help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QSortFilterProxyModel search and view scroll help

    I have a QSqlTableModel and a QTableView. Trying to sort through the model, find a record, then scroll to it in the view.
    Here is the code, where strID is a string to search for, like "89".

    Qt Code:
    1. proxy.setSourceModel(model);
    2.  
    3. proxy.setFilterKeyColumn(0);
    4. proxy.setFilterFixedString(strID);
    5. vidx = proxy.mapToSource(proxy.index(0, 0));
    6.  
    7. if (vidx.isValid())
    8. {
    9. view->selectionModel()->select(vidx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    10. view->scrollTo(vidx, QAbstractItemView::EnsureVisible);
    11. }
    To copy to clipboard, switch view to plain text mode 

    I am having two problems.

    1. If the header sort is set to column 0 ascending, and the record found has a sequential value in column 0 of more than 256, the scrollTo does not work, 256 or less and it works fine.

    2. if the header sort is set to column 0 descending, and the record found has a sequential value in column 0 of 89 for example, the view scrolls to the record with 289 in column 0.

    Any advice as to how to overcome these problems greatly appreciated.

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSortFilterProxyModel search and view scroll help

    Didn't seem to be able to edit this post.

    Here is the update: problem number 2 has been solved with the following code:
    Qt Code:
    1. proxy.setFilterKeyColumn(0);
    2. QRegExp exp("^"+lastID+"$");
    3. proxy.setFilterRegExp(exp);
    To copy to clipboard, switch view to plain text mode 
    It now matches only the whole string. Some success.

    No luck with problem number 1. QSortFilterProxyModel does not seem to work with a record more than 256 rows down from the top, no matter how the view is sorted. vidx comes back invalid in those cases. No idea why.

    Come on experts, I need some help here! Anyone else having this problem?
    Thanks for any advice.

Similar Threads

  1. Replies: 0
    Last Post: 2nd February 2011, 12:02
  2. Replies: 2
    Last Post: 10th May 2010, 13:13
  3. QSortFilterProxyModel and search
    By vr in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2007, 13:37
  4. Replies: 1
    Last Post: 18th July 2006, 10:53
  5. Scroll View for Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 25th March 2006, 07:19

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.