QTAbleView Not scrolling
-
wrote on 28 Jun 2013, 06:25 last edited by
HI,
I have QTableView with so many rows in it Such that the last row wont be visible. Only first 10 rows are visible in the screen . For viewing others we need to scroll.
I wanted to show the last row progrmatically. I use tableview->scrollTo(QModelIndex i) function. "i" is the model index of last row. But this is not working. May i know what is the reason and how to solve it? -
scrollTo() is the correct way to do it. So the problem must be somewhere else in your code...
Maybe you call it too early? Show us some code please... -
Hi,
Also, what version of Qt are you using and on what OS ?
-
wrote on 28 Jun 2013, 08:19 last edited by
QT4 and centOS
-
and the code?
-
wrote on 28 Jun 2013, 08:35 last edited by
TableModel *temp_model ;
//TableModel has data in it.
//element is the TableViewfor(int i=0;i<temp_model->rowCount();i++) { for(int j=0;j<temp_model->columnCount();j++) { if(some condition to enter the function) QModelIndex ii=temp_model->index(i,j); element->scrollTo(ii); } } }
-
Please encode your code between coding tags.
Are you sure element->scrollTo is called ?
-
wrote on 28 Jun 2013, 08:48 last edited by
If TableModel is derived from QSqlTableModel then you need to read about canFetchMore() and fetchMore() because rowCount() may not return the number of the last row in the table.
Also, it helps if you describe what "it doesn't work" actually means. What were you expecting, what did it actually do, what have you tried to fix it etc.
-
wrote on 28 Jun 2013, 08:58 last edited by
@TableModel *temp_model ;
//TableModel has data in it.
//element is the TableView
for(int i=0;i<temp_model->rowCount();i++) {
for(int j=0;j<temp_model->columnCount();j++) {
if(some condition to enter the function)
QModelIndex ii=temp_model->index(i,j);
element->scrollTo(ii);
}
}
} @ -
wrote on 28 Jun 2013, 22:53 last edited by
The code you have posted will not compile. The if statement at line 6 terminates at line 7. At line 8 there is no variable called "ii" in scope (unless there is an "ii" at wider scope, in which case it may compile and not do what you expect). Line 11 does not have a matching "{" in the snippet.
Why are you trying to scrollTo() every single index in the table? If want the "bottom" of the table then you can get that directly:
@
QModelindex bottomLeft = model->index(model->rowCount() - 1, 0);
view->scrollTo(bottomLeft);
// OR
QModelindex bottomRight = model->index(model->rowCount() - 1, model->columnCount() - 1);
view->scrollTo(bottomRight);
@
3/10