Results 1 to 6 of 6

Thread: QTableView not scrolling

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

    Default QTableView not scrolling

    I have a model/view where the code searches for the value in a field.

    The correct row is always selected ok, but the view does not scroll so the selected row is visible.

    Qt Code:
    1. proxy.setSourceModel(model);
    2. proxy.setFilterKeyColumn(1);
    3. proxy.setFilterFixedString(ui->mwCall->text());
    4. vidx = proxy.mapToSource(proxy.index(0,0));
    5. view->selectionModel()->select(vidx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    6. view->scrollTo(vidx, QAbstractItemView::EnsureVisible);
    To copy to clipboard, switch view to plain text mode 

    Any ideas as to how to fix this to make it scrollTo correctly?

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView not scrolling

    Quote Originally Posted by waynew View Post
    Any ideas as to how to fix this to make it scrollTo correctly?
    I don’t know what’s wrong, but I can suggest the way I would proceed: run it under the debugger with a breakpoint on the scrollTo line. Step into the QTableView::scrollTo implementation and see if you can spot where it’s going awry. That might give you a hint as to why it is failing.

  3. The following user says thank you to Coises for this useful post:

    waynew (16th February 2010)

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

    Default Re: QTableView not scrolling

    Well Coises, I can't see where it is going wrong in the debugger.
    I am wondering if it makes a difference that the search is executed from the main window and when it completes, the main window still has focus, not the view window. However, the row still gets selected and highlighted correctly in the view window. If the selected row is not visible and you manually scroll the view window you can find it and it is selected ok. So I guess I'm at a loss here - will just keep researching and see if I can come up with something.

    Another cat lover? I have 3 white ones.

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

    Default Re: QTableView not scrolling

    Ok, solved. I was hiding the primary key column from the database/model in the view and this was the field the search was based on.
    Now if I setColumnHidden(0,FALSE) when starting the search, then setColumnHidden(0,TRUE) after the scrollTo, it works fine.

    For the benefit of anyone else needing this, here is the code that works:

    Qt Code:
    1. if (vidx.isValid()) {
    2. view->setColumnHidden(0, FALSE);
    3. view->selectionModel()->select(vidx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    4. view->scrollTo(vidx, QAbstractItemView::EnsureVisible);
    5. view->setColumnHidden(0, TRUE);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by waynew; 16th February 2010 at 02:08.

  6. #5
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView not scrolling

    I’m glad you found the answer, and thanks for posting it so others can find it.

    Yes, I’m a cat lover. Though my namesake, Coises!, died in 2005, I’ve yet to get another. I’m holding out until my own life feels stable. It’s looking like a long wait...

  7. #6
    Join Date
    Apr 2008
    Location
    Pittsburgh,PA,USA
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView not scrolling

    I just had the same issue. I wasted abut 1 hour trying to figure out why I could not scroll to the selected item. It ended up being the same cause the quite a few of my columns are hidden (from a database query) and the column I was trying to scroll to was one of the hidden columns.

    Thanks,
    John
    John

Similar Threads

  1. How to track scrolling
    By Slewman in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2010, 23:45
  2. Scrolling QTextEdit
    By mirluk in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 30th November 2009, 08:59
  3. QScrollArea scrolling down not up
    By ntp in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 17:23
  4. QPlainTextEdit scrolling
    By roxton in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 16:55
  5. Scrolling items in QTableView
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2007, 12:59

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.