How to disable QTableWidget scrolling to selected cell?

后端 未结 2 365
-上瘾入骨i
-上瘾入骨i 2021-01-23 11:05

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 t

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 11:24

    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.

提交回复
热议问题