Results 1 to 5 of 5

Thread: determining visible rows/columns of a QTableView/QTreeView

  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default determining visible rows/columns of a QTableView/QTreeView

    How can the visible rows/columns of a QTableView (and QTreeView) be determined?
    More specifically, how can a QModelIndex be created for the currently visible top-left and bottom-right items?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: determining visible rows/columns of a QTableView/QTreeView

    I'm not sure what you mean by 'top-left' and 'bottom-right' items.
    Could you elaborate?

    Meantime take a look at QItemSelectionModel.

  3. #3
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: determining visible rows/columns of a QTableView/QTreeView

    Perhaps an example will demonstrate ...

    There is a QTableView that is presenting data like a spreadsheet.
    The data are 10 columns (A-J) by 100 rows (1-100).
    At any time, only some columns (variable width) and some rows can be scrolled into view.

    My question is:
    How can I determine what data items are currently viewable?
    If I know what data items are being viewed in the top-left corner and bottom-right corner,
    then I can know all of the data items that are in view.

    Row, Column for each corner would be great.
    A ModelIndex for each corner would be great.
    But, I cannot figure out how to interrogate the QTableView for any helpful corner information.


    Also:
    QItemSelectionModel does not help, because I am not dealing with selected items, just items that are viewable.
    Last edited by mule; 7th February 2012 at 15:21.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: determining visible rows/columns of a QTableView/QTreeView

    Ok, I get it now.

    That's actually very easy:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. :
    3. QMainWindow(parent),
    4. table( new QTableWidget() )
    5. {
    6. this->table->setRowCount( 100 );
    7. this->table->setColumnCount( 10 );
    8.  
    9. this->setCentralWidget( this->table );
    10.  
    11. QToolBar* tb = this->addToolBar( "Test" );
    12. tb->addAction( "Test", this, SLOT( test() ) );
    13. }
    14.  
    15. void MainWindow::test( void )
    16. {
    17. qDebug() << this->table->rowAt( 0 ) << "-" << this->table->rowAt( this->table->height() ); // this is what you want
    18. qDebug() << this->table->columnAt( 0 ) << "-" << this->table->columnAt( this->table->width() ); // this is what you want
    19. }
    To copy to clipboard, switch view to plain text mode 
    Edit:
    You can also use indexAt( table->rect.topLeft() ) and indexAt( table->rect().bottomRight() ) if index is more convenient for you.
    Last edited by Spitfire; 7th February 2012 at 15:49.

  5. The following 2 users say thank you to Spitfire for this useful post:

    Ashkan_s (10th October 2012), mule (8th February 2012)

  6. #5
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: determining visible rows/columns of a QTableView/QTreeView

    Yes! That is it!
    Both (rowAt,columnAt and indexAt) will be extremely helpful.

    Thank you.

Similar Threads

  1. Replies: 2
    Last Post: 15th August 2011, 00:26
  2. Static/Fixed rows and columns in a QTreeView
    By code_talker in forum Qt Programming
    Replies: 0
    Last Post: 27th April 2011, 13:00
  3. Weird problem resizing rows and columns in qtableview
    By Tiansen in forum Qt Programming
    Replies: 1
    Last Post: 27th December 2010, 14:26
  4. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  5. Making rows visible in QTableView
    By derrickbj in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 16:38

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.