Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView scroll to new added row

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.

like image 220
Ashot Avatar asked Sep 30 '13 19:09

Ashot


2 Answers

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.

like image 180
Pavel Strakhov Avatar answered Nov 03 '22 00:11

Pavel Strakhov


view->scrollToBottom(); is better solution, because if using scrollTo metthod, new row in some cases is not full visible

like image 44
alex Avatar answered Nov 03 '22 01:11

alex