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?
Printable View
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?
I'm not sure what you mean by 'top-left' and 'bottom-right' items.
Could you elaborate?
Meantime take a look at QItemSelectionModel.
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.
Ok, I get it now.
That's actually very easy:
Edit:Code:
: { this->table->setRowCount( 100 ); this->table->setColumnCount( 10 ); this->setCentralWidget( this->table ); tb->addAction( "Test", this, SLOT( test() ) ); } void MainWindow::test( void ) { qDebug() << this->table->rowAt( 0 ) << "-" << this->table->rowAt( this->table->height() ); // this is what you want qDebug() << this->table->columnAt( 0 ) << "-" << this->table->columnAt( this->table->width() ); // this is what you want }
You can also use indexAt( table->rect.topLeft() ) and indexAt( table->rect().bottomRight() ) if index is more convenient for you.
Yes! That is it!
Both (rowAt,columnAt and indexAt) will be extremely helpful.
Thank you.