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. Need to trigger a scrollTo after layout is finished with layoutMode=Batched
Forum Updated to NodeBB v4.3 + New Features

Need to trigger a scrollTo after layout is finished with layoutMode=Batched

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 775 Views 2 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.
  • ssokolowS Offline
    ssokolowS Offline
    ssokolow
    wrote on last edited by
    #1

    I've used QSortFilterProxyModel to hook a filter box up to a couple of views and I'm trying to use QAbstractItemView::scrollTo to ensure that the selected item remains within the viewport if the filter changes and the item is still a match.

    However, when I tested the obvious approach, it appeared to be failing when I backspaced the search pattern down to a single letter.

    Given the following characteristics I managed to identify, it's pretty clear that "scrollTo is being called before layout finishes" is the problem:

    1. Changing layoutMode from Batched to SinglePass works around the problem.
    2. On my test data set, it will probabilistically work if I use a QTimer to delay it by 10ms and will reliably work if I delay it by 25ms.

    So, what I need to know is how to arrange for scrollTo to be run once layout finishes.

    I tried connecting to QAbstractSlider::rangeChanged but it didn't solve the problem despite the handler firing (which suggests to me that it's firing after the canvas is expanded but before the item is positioned sufficiently for it to be used as a point of reference).

    I've also checked...

    1. The "all members, including inherited" view on the QAbstractItemView docs
    2. Google with various mixes of keywords

    ... but nothing looked relevant.

    kshegunovK 1 Reply Last reply
    0
    • ssokolowS ssokolow

      I've used QSortFilterProxyModel to hook a filter box up to a couple of views and I'm trying to use QAbstractItemView::scrollTo to ensure that the selected item remains within the viewport if the filter changes and the item is still a match.

      However, when I tested the obvious approach, it appeared to be failing when I backspaced the search pattern down to a single letter.

      Given the following characteristics I managed to identify, it's pretty clear that "scrollTo is being called before layout finishes" is the problem:

      1. Changing layoutMode from Batched to SinglePass works around the problem.
      2. On my test data set, it will probabilistically work if I use a QTimer to delay it by 10ms and will reliably work if I delay it by 25ms.

      So, what I need to know is how to arrange for scrollTo to be run once layout finishes.

      I tried connecting to QAbstractSlider::rangeChanged but it didn't solve the problem despite the handler firing (which suggests to me that it's firing after the canvas is expanded but before the item is positioned sufficiently for it to be used as a point of reference).

      I've also checked...

      1. The "all members, including inherited" view on the QAbstractItemView docs
      2. Google with various mixes of keywords

      ... but nothing looked relevant.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Hello,
      Use a single pass layout. The other thing doesn't make much sense. The idea of the batched mode layout is that you don't need to calculate the positions and sizes of all the items at once, but only for the ones that are shown (thus you batch the work and process events in the mean time). When you request a scrollTo there's no way the position (screen/logical coordinates) is known before the item is laid out, which defeats the whole purpose of having a batched laying out technique, i.e. a deferred position and size calculation from the view.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      ssokolowS 1 Reply Last reply
      1
      • kshegunovK kshegunov

        Hello,
        Use a single pass layout. The other thing doesn't make much sense. The idea of the batched mode layout is that you don't need to calculate the positions and sizes of all the items at once, but only for the ones that are shown (thus you batch the work and process events in the mean time). When you request a scrollTo there's no way the position (screen/logical coordinates) is known before the item is laid out, which defeats the whole purpose of having a batched laying out technique, i.e. a deferred position and size calculation from the view.

        Kind regards.

        ssokolowS Offline
        ssokolowS Offline
        ssokolow
        wrote on last edited by
        #3

        @kshegunov Ahh, that makes sense. Thanks.

        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