Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unlogical running of scrollTo() in QTableView
Qt 6.12 LTS is out! See what's new in the release blog

Unlogical running of scrollTo() in QTableView

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.4k 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.
  • francescmmF Offline
    francescmmF Offline
    francescmm
    wrote on last edited by
    #1

    I have a playlist table inherited from QTableView that periodically changes of line. It has also an autoScroll method that tries to scroll automatically to next line if it is not visible in the QTableView::vierport().

    The problem is that some times the current playing line is located in a specific row i.e. 500 and I want to scrollTo() the 2000. I have debugged Qt and I have seen that it stores the new value but does not scroll due to the new viewport doesn't intersects with the old. The reason seems that it is done for performance reasons as it is explained in a comment at QAbstractItemView::update().

    Is there any way to force the line scroll change?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      QAbstractItemView::update() just doesn't repaint rects that do not intersect with the viewport's rect. Since scrollTo() adjusts the scrollbars beforehand the repaint should happen in all cases (when scrollTo() is called).

      The problem is that scrollTo() is implemented in such a way that it does not update the scrollbars when the index' visualRect is already inside the viewport.

      A dirty hack would be to call "QAbstractItemView::scrollToTop()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#scrollToTop first and then call scrollTo().
      If that doesn't lead to a desired result you have to subclass QTableView class and reimplement scrollTo() (since it's virtual).

      --- 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
      • francescmmF Offline
        francescmmF Offline
        francescmm
        wrote on last edited by
        #3

        Finally, what I have done is to calculate the row range of the row that I want to visualize and in this case, force the call to the method again. Is not elegant, but in this case it runs... I think that the next step is to reimplement scrollTo() since my table is already subclassed from QTableView.

        Could this method be considered a bug or could be purposed to be changed?

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