scrollTo not working properly



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

    gameList->selectRow(row);
    gameList->sortByColumn(m_sortColumn, m_colSortOrder);
    gameList->verticalHeader()->setMinimumSectionSize(m_Icon_Size.height());
    gameList->verticalHeader()->setMaximumSectionSize(m_Icon_Size.height());
    gameList->resizeRowsToContents();
    gameList->resizeColumnToContents(0);
    gameList->scrollTo(gameList->currentIndex(), QAbstractItemView::PositionAtCenter);
    

    Adding

    gameList->scrollToBottom();
    gameList->scrollToTop();
    

    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.

    Thx



  • @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

    @Megamouse
    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()
    {
        scheduleDelayedItemsLayout();
        executeDelayedItemsLayout();
    }
    


  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.