Results 1 to 4 of 4

Thread: QTableView selected row not in visible area

  1. #1
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default QTableView selected row not in visible area

    Hello,

    If, due to logic, I select a row in my table the selected row is not automaticaly scrolled to the visible area of the TableView.

    Qt Code:
    1. // Get model index based on markerId
    2. QModelIndexList indexList (m_markerProjectionModel->match (m_markerProjectionModel->index (0,0), Qt::DisplayRole, markerId, 1, Qt::MatchExactly));
    3. if (1 == indexList.count ())
    4. {
    5. m_markersProjectionTableView->selectRow (indexList [0].row ());
    6. }
    To copy to clipboard, switch view to plain text mode 

    How can I get the selected item always visible in the visible area?

    regards,

    Marcel

  2. #2
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selected row not in visible area

    I never tried, but perhaps you can use a call to scrollTo :

    Qt Code:
    1. // Get model index based on markerId
    2. QModelIndexList indexList (m_markerProjectionModel->match (m_markerProjectionModel->index (0,0), Qt::DisplayRole, markerId, 1, Qt::MatchExactly));
    3. if (1 == indexList.count ())
    4. {
    5. m_markersProjectionTableView->selectRow (indexList [0].row ());
    6. m_markersProjectionTableView->scrollTo( indexList[0]); // <= ADD THIS LINE
    7. }
    To copy to clipboard, switch view to plain text mode 

    See HERE

  3. #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 selected row not in visible area

    m_markersProjectionTableView->scrollTo( indexList[0]); // <= ADD THIS LINE
    I would add to that:
    Qt Code:
    1. m_markersProjectionTableView->scrollTo( indexList[0], QAbstractItemView::EnsureVisible);
    To copy to clipboard, switch view to plain text mode 
    I have similar code and it always scrolls to the selected row.

  4. #4
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selected row not in visible area

    If you look at documentation, you can see this :

    Qt Code:
    1. void QAbstractItemView::scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible ) [pure virtual]
    To copy to clipboard, switch view to plain text mode 

    so no real need of 2nd parameter here ( only if you want to use PositionAtTop, PositionAtBottom, PositionAtCenter )

Similar Threads

  1. Replies: 2
    Last Post: 26th May 2010, 06:33
  2. Replies: 1
    Last Post: 9th December 2009, 08:44
  3. QTextArea getting the current line of visible area(scroll)
    By ubuntudevelop78 in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2009, 06:19
  4. How to copy selected ellipse area from image
    By adamsakli in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 19:54
  5. Replies: 1
    Last Post: 19th January 2007, 11:28

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.