Important: Please read the Qt Code of Conduct -

scrollTo not working properly

  • When using this code inside a tablewidget refresh function the scrollTo sometimes jumps to undefined places.

    gameList->sortByColumn(m_sortColumn, m_colSortOrder);
    gameList->scrollTo(gameList->currentIndex(), QAbstractItemView::PositionAtCenter);



    directly in front of the scrollTo(...) fixes this weird issue. The scroll now always centers the desired row.

    We are wondering if this is a Qt bug or if we missed something.
    It's not really that important since the workaround is doing fine, but we are really curious if that can be avoided.


  • @Megamouse
    I am not the expert but what I heard is that there is some kind of delay on scrollTo() function. So I had to use singleshot 500ms to make it work properly.

  • Moderators

    what data does your list view contain? Does it contain multi-line text?
    I guess not all of your items are layouted yet when you call scrollTo()?

    Try the following (you need to subclass the list view widget since the methods are protected):

    void myListView::layoutItems()

  • So: after the hint with toScroll delay we noticed that the table layout/state might not be fully up to date with its contents.
    I went through the table-filling code step by step and found that one of our devs used setRowCount(0); to clear the table without losing the headers .
    I replaced it with clearContents(); and now it seems to be working.

    If it still has issues I may try the schedule .

    Thanks for the inspiration!

Log in to reply