QTableView滚动到新增的行 [英] QTableView scroll to new added row
本文介绍了QTableView滚动到新增的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要为模型添加新行,我将调用 beginInsertRows
和 endInsertRows()
。如何配置视图以滚动到新添加的行并选择它。
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.
推荐答案
在表单类中创建一个插槽,将其连接到模型的 rowsInserted
信号。该槽应包含以下内容:
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.
这篇关于QTableView滚动到新增的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文