To add new rows to model I am calling beginInsertRows
and endInsertRows()
. How to configure the view to scroll to new added rows and select it. I can do it by sending some signals but maybe Qt has standard way for it.
Asked
Active
Viewed 1.3k times
9

Ashot
- 10,807
- 14
- 66
- 117
2 Answers
14
Create a slot in your form class and connect it to the model's rowsInserted
signal. The slot should contain the following:
void My_form::model_rows_inserted(const QModelIndex & parent, int start, int end) {
view->scrollTo(model->index(start, 0));
}
Note that you cannot (and should not) do this from your model. The model should know nothing about the view.

Kuba hasn't forgotten Monica
- 95,931
- 16
- 151
- 313

Pavel Strakhov
- 39,123
- 5
- 88
- 127
8
view->scrollToBottom();
is better solution, because if using scrollTo metthod, new row in some cases is not full visible

alex
- 89
- 1
- 1
-
3This wouldn't work if there was some sorting being done on the QTableView. – Shadow9043 Sep 29 '14 at 09:09