Results 1 to 2 of 2

Thread: How to set visible row in QTableView?

  1. #1
    Join Date
    Aug 2009
    Posts
    56
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default How to set visible row in QTableView?

    QTableView *tableViewWidget;
    int from;

    I want to make tableViewWidget scroll down to show the row such that 'from' is the first row displayed.

    I've tried all of the following over the last half hour, without success

    Qt Code:
    1. tableViewWidget->showRow(from);
    2. tableViewWidget->selectRow(from);
    3. QModelIndex modelIndex = tableViewWidget->indexAt(QPoint(0,from));
    4. tableViewWidget->scrollTo(modelIndex);
    To copy to clipboard, switch view to plain text mode 

    I traced through scrollTo, and it works (the index is valid). But the view doesn't update.

    I appreciate any help.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set visible row in QTableView?

    Unless I am misunderstanding the docs,
    Qt Code:
    1. QModelIndex modelIndex = tableViewWidget->indexAt(QPoint(0,from));
    2. tableViewWidget->scrollTo(modelIndex);
    To copy to clipboard, switch view to plain text mode 
    Will find the index of the row that is currently at the top-left of the view and scroll to it. This should result in not much movement. I think what you wanted was something like:
    Qt Code:
    1. QModelIndex modelIndex = model->index(from, 0, QModelIndex());
    2. tableViewWidget->scrollTo(modelIndex, QAbstractItemView::PositionAtTop);
    To copy to clipboard, switch view to plain text mode 
    i.e. find the index of the desired row and scroll to it.

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

    rakkar (22nd September 2009)

Similar Threads

  1. Replies: 1
    Last Post: 18th September 2009, 20:18
  2. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  3. How to tell if QTableView cell is visible ?
    By steviekm3 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2009, 10:04
  4. How to tell if cell in QTableView is visible ??
    By steviekm3 in forum Qt Programming
    Replies: 3
    Last Post: 27th February 2009, 17:57
  5. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49

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.