How to update QTableWidget scrollbar positions?

  • Hi,
    I am working on a QTableWidget object that I have to update with data coming from a network socket. There is a selection action that happens from time to time, but although I am using scrollbars, the viewport of the QTableWidget is not showing the area where the selected cells are.

    Question: Is there a way to force the QTableWidget to update its viewport everytime I update the selected cells from code?


  • Maybe:

    void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible)

  • Lifetime Qt Champion


    Not sure to get you, do you mean that the selection gets out of view and that you'd like to re-center on it when there's an update ?

  • @SGaist Exactly! The new selection is not visible, so I have to move the scroll bars manually to center the new selected cells.

  • Lifetime Qt Champion

    Using scrollTo ?

  • The method QTableWidget::scrollToItem() made the magic for me. It works perfect!ly :)


Log in to reply