QTableView how to get the scroll bar row position

6.5k views Asked by At
void scrollBarValueChanged(int value)
{
     int row = view->rowAt(value);
}

Such as the title, when the scroll bar rolling, how to get the scroll row index?

2

There are 2 answers

0
Антон Сергунов On BEST ANSWER

Looks like rowAt and columnAt are exactly what you need.

0
Farhad On

Use horizontalScrollBar() verticalScrollBar() functions and get scroll value from it.

QScrollBar *verticalScroll = ui->tableView->verticalScrollBar();
QScrollBar *horizontalScroll = ui->tableView->horizontalScrollBar();
int valueV = verticalScroll->value();
int valueH = horizontalScroll->value();

Also use scrollTo function to scroll to your table cell index. (horizontally and vertically)

ui->tableView->scrollTo( ui->tableView->model()->index(row,column) );

like this image:

ui->tableView->scrollTo(ui->tableView->model()->index(7,3));

screenshot

The QTableView page on Qt website.