恢复QTableView中的垂直滚动
Restoring vertical scroll in QTableView
我使用C++、Qt 4.8.7、Visual Studio 2013、Windows 7。我的GUI应用程序包含QTableView
。我添加了插槽,用于处理来自我的模型的beginResetModel()
和reset()
信号。这些槽通常被调用,但垂直滚动仍然始终滚动到整个列表的顶部。我该怎么修?我需要恢复当前位置。请注意,在重置期间,不会删除任何行。因此,可以更改旧的行内容和/或添加新行。
//before reset
current_top_row_number_ = table_view_->rowAt(0);
//after reset
table_view_->scrollTo(log_model_->index(current_top_row_number_, 0), QAbstractItemView::PositionAtTop);
尝试排队呼叫scrollTo
,例如
class MyWidget : public MyWidget {
Q_OBJECT
int current_top_row_number_;
QTableView table_view_;
Q_SLOT void onResetModel() {
table_view_->scrollTo(log_model_->index(current_top_row_number_, 0),
QAbstractItemView::PositionAtTop);
}
...
public:
MyWidget(QWidget * parent = nullptr) : QWidget{parent} {
connect(table_view_, SIGNAL(modelReset()), SLOT(onResetModel(), Qt::QueuedConnection);
}
};
相关文章:
- 使用一个考虑到std::map中键值的滚动或换行的键
- QScrollArea:由垂直滚动条引起的水平滚动条
- 跟踪滚动条上的鼠标事件
- 垂直方向的 Gtk3+ 旋转按钮 (c/c++)
- 如何在不使用滚动条的情况下使视图更改
- OnVScroll : 从 CSpinButtonCtrl 或垂直滚动条调用?
- 如何使用C++获取/设置OBS中的垂直滚动过滤器属性?
- 如何在移动列表视图中添加滚动条?并且用户只能垂直滚动特定区域
- C 如何删除垂直滚动条
- 如何知道垂直滚动条何时显示?
- 列表视图中的 CListCtrl 垂直滚动条
- QScroll区域与垂直滚动的问题
- 如何获得鼠标滚轮垂直滚动速率
- 在cocos2d-x中垂直滚动图像
- MFC CCheckListBox 的垂直滚动条未更新
- QTreeWidget垂直滚动条跳得太远
- 如何在qcombox中放大垂直滚动条的宽度
- 如何防止垂直滚动条闪烁在CListCtrl重新填充其项目后
- 总是显示wxHtmlWindow垂直滚动条
- 恢复QTableView中的垂直滚动