Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. scrollTo not working properly
Qt 6.11 is out! See what's new in the release blog

scrollTo not working properly

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by Megamouse
    #1

    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

    S raven-worxR 2 Replies Last reply
    0
    • MegamouseM Megamouse

      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

      S Offline
      S Offline
      samdol
      wrote on last edited by
      #2

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

      1 Reply Last reply
      1
      • MegamouseM Megamouse

        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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @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();
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • MegamouseM Offline
          MegamouseM Offline
          Megamouse
          wrote on last edited by Megamouse
          #4

          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!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved