如何禁用 QTableWidget 滚动到选定的单元格?
目前,如果用户单击仅部分可见的单元格,窗口会自动滚动以使该单元格完全显示。有什么办法可以阻止表这样做吗?谢谢
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过以下方式轻松禁用此行为:
alexisdm 的答案正在处理另一个问题。假设您正在向表中增量追加新行,并且希望保持当前的垂直滚动位置。我正在处理第二个问题,alexisdm的答案似乎很有希望。
You can easily disable this behavior with:
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.
滚动是由
QAbstractItemView
完成的,它调用虚拟函数scrollTo
并索引提示EnsureVisible
。您无法阻止调用,因为它是通过私有计时器完成的,但您可以更改scrollTo
函数的功能:并且为了仍然能够手动滚动到某个项目,您可以编写另一个将调用
QTableWidget::scrollTo
的成员函数。The scrolling is done by
QAbstractItemView
which call the virtual functionscrollTo
with index the hintEnsureVisible
. You can't prevent the call, because it is done through a private timer, but you can change what thescrollTo
function does:And to still be able to scroll to an item manually, you could write another member function that would call
QTableWidget::scrollTo
.