QTableView scroll to new added row
12,524
Solution 1
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.
Solution 2
view->scrollToBottom();
is better solution, because if using scrollTo metthod, new row in some cases is not full visible
![Ashot](https://i.stack.imgur.com/har6o.jpg?s=256&g=1)
Author by
Ashot
Updated on July 23, 2022Comments
-
Ashot almost 2 years
To add new rows to model I am calling
beginInsertRows
andendInsertRows()
. 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. -
Shadow9043 over 9 yearsThis wouldn't work if there was some sorting being done on the QTableView.