How to disable QTableWidget scrolling to selected cell?

蹲街弑〆低调 提交于 2019-12-02 03:18:11

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.

Ali

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!