Need to trigger a scrollTo after layout is finished with layoutMode=Batched
QSortFilterProxyModelto hook a filter box up to a couple of views and I'm trying to use
QAbstractItemView::scrollToto 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 "
scrollTois being called before layout finishes" is the problem:
layoutModefrom Batched to SinglePass works around the problem.
- On my test data set, it will probabilistically work if I use a
QTimerto 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
scrollToto be run once layout finishes.
I tried connecting to
QAbstractSlider::rangeChangedbut 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
- Google with various mixes of keywords
... but nothing looked relevant.
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
scrollTothere'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.
@kshegunov Ahh, that makes sense. Thanks.