我使用QTreeView和QSortFilterProxyModel
// Here I determine the index, that was saved before (_lastAddObjectIndex - QModelIndex)
QModelIndex next_index = _proxyModel->index(_lastAddObjectIndex.row(), 0);
// Here I select the row programmatically, and after that I'd like to move to that row (because table might have many rows)
view->selectionModel()->select(next_index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
我认为移动意味着滚动。如果是这样,您可以通过使用以下API:来实现这一点
view->scrollTo(next_index);
如果将第二个参数传递给该方法,您甚至可以更改滚动提示。这取决于您是否对默认值满意,默认值只是确保项目可见。
您可以参考文档来进一步微调这种行为,以备不时之需。