Skip to content

Reduce the width of a hfw-widget if scrollbar would be flipping

Here are two commits that, if picked, should definitely go together. May need some runtime testing, as pointed out by the second commit: The number of calls is still very high during showing and resizing; optimizing this further is for a separate commit. No further commit was made to the file in question yet, though.

[PATCH 1/2] Reduce the width of a hfw-widget if scrollbar would be flipping

For a widget that implements height-for-width, the vertical scrollbar
becoming visible might be just enough to make the scrollbar unnecessary.
In that situation, the scrollbar flips on and off continuously.

To avoid that situation, make the width of the widget smaller until the
height fits without scrollbar, up to the point where we have space for
the scrollbar anyway.

The calcuation here is assumed to be cheap, but depends on the
heightForWidth implementation in the widget. Running the while-loop a
few dozen times should have no performance impact during resizing
and laying out the scroll area contents.

Add a test that confirms that within a brief period of time we only get
the one hide-event we expect.

Done-with: Zou Ya <zouya@uniontech.com>
Fixes: QTBUG-92958
Pick-to: 6.2 5.15
Change-Id: I0faeb5f9b1a226aada958c18333d9c2ac8203dd1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 6c4dc722cb9bf765904feefff4fb00bdb0b3dc9f)

[PATCH 2/2] Fix performance regression when avoiding scrollbar flipping

Amends 6c4dc722cb9bf765904feefff4fb00bdb0b3dc9f.

Don't search for the optimal size of the scrollarea's widget if it can't
be found anyway. Try the size with scrollbar first, which covers the
vast majority of sizes.

Optimizing the loop with e.g. a binary search adds no value, as the size
is often just a pixel too small.

Since we can't rely on the number of height-for-width calls, we can't
meaningfully test this behavior. The number of calls is still very high
during showing and resizing; optimizing this further is for a separate
commit.

Fixes: QTBUG-97811
Pick-to: 6.2 5.15
Change-Id: If145302e6414b32cf1ce7251ff33b0039f584867
Reviewed-by: Jonas Kvinge's avatarJonas Kvinge <jonas@jkvinge.net>
Reviewed-by: default avatarRichard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit ffc9323671d045e3566980d9ed4567f071004e65)

Merge request reports