本文介绍了如何禁用 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

推荐答案

滚动是由 QAbstractItemView 完成的,它调用虚函数 scrollTo 和索引提示 确保可见.您无法阻止调用,因为它是通过私人计时器完成的,但是您可以更改 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);
}

为了仍然能够手动滚动到一个项目,您可以编写另一个成员函数来调用 QTableWidget::scrollTo.

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

这篇关于如何禁用 QTableWidget 滚动到选定单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:13