PDA

View Full Version : How to set visible row in QTableView?



rakkar
21st September 2009, 18:42
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



tableViewWidget->showRow(from);
tableViewWidget->selectRow(from);
QModelIndex modelIndex = tableViewWidget->indexAt(QPoint(0,from));
tableViewWidget->scrollTo(modelIndex);


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

I appreciate any help.

ChrisW67
21st September 2009, 23:23
Unless I am misunderstanding the docs,


QModelIndex modelIndex = tableViewWidget->indexAt(QPoint(0,from));
tableViewWidget->scrollTo(modelIndex);

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:


QModelIndex modelIndex = model->index(from, 0, QModelIndex());
tableViewWidget->scrollTo(modelIndex, QAbstractItemView::PositionAtTop);

i.e. find the index of the desired row and scroll to it.