Need to trigger a scrollTo after layout is finished with layoutMode=Batched
-
I've used
QSortFilterProxyModel
to hook a filter box up to a couple of views and I'm trying to useQAbstractItemView::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:- Changing
layoutMode
from Batched to SinglePass works around the problem. - 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...
- The "all members, including inherited" view on the
QAbstractItemView
docs - Google with various mixes of keywords
... but nothing looked relevant.
- Changing
-
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 ascrollTo
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.