如何禁用 QTableWidget 滚动到选定的单元格?

发布于 2024-12-01 13:51:34 字数 61 浏览 5 评论 0原文

目前,如果用户单击仅部分可见的单元格,窗口会自动滚动以使该单元格完全显示。有什么办法可以阻止表这样做吗?谢谢

Currently, if the user clicks on a cell that is only partially visible, the window automatically scrolls over so that the cell is fully displayed. Is there any way to stop the table doing this? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

擦肩而过的背影 2024-12-08 13:51:34

您可以通过以下方式轻松禁用此行为:

ui->tableWidget->setAutoScroll(false);

alexisdm 的答案正在处理另一个问题。假设您正在向表中增量追加新行,并且希望保持当前的垂直滚动位置。我正在处理第二个问题,alexisdm的答案似乎很有希望。

You can easily disable this behavior with:

ui->tableWidget->setAutoScroll(false);

alexisdm's answer is dealing with another problem. Suppose you are incrementally appending new rows to your table and you want to maintain current vertical scroll position. I am dealing with this second problem and alexisdm's answer seems promising.

長街聽風 2024-12-08 13:51:34

滚动是由 QAbstractItemView 完成的,它调用虚拟函数 scrollTo 并索引提示 EnsureVisible。您无法阻止调用,因为它是通过私有计时器完成的,但您可以更改 scrollTo 函数的功能:

void TableWidget::scrollTo(const QModelIndex &index, ScrollHint hint)
{
    if(hint == QAbstractItemView::EnsureVisible)
        return;
    QTableWidget::scrollTo(index, hint);
}

并且为了仍然能够手动滚动到某个项目,您可以编写另一个将调用QTableWidget::scrollTo的成员函数。

The scrolling is done by QAbstractItemView which call the virtual function scrollTo with index the hint EnsureVisible. You can't prevent the call, because it is done through a private timer, but you can change what the scrollTo function does:

void TableWidget::scrollTo(const QModelIndex &index, ScrollHint hint)
{
    if(hint == QAbstractItemView::EnsureVisible)
        return;
    QTableWidget::scrollTo(index, hint);
}

And to still be able to scroll to an item manually, you could write another member function that would call QTableWidget::scrollTo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文