QAbstractScrollArea: don't call QScrollBar::sizeHint unless we need to

We only take the scrollbar's extent into account if the respective
policy is Qt::ScrollBarAlwaysOn, so don't compute it otherwise.

Done-with: Ilya Fedin <fedin-ilja2010@ya.ru>
Change-Id: Idaf9404860d1f778d7a89b19d9f7fc16201ce29e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 68f35a571a259cd83490c093af01d8b4e9b0e34a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Yuhang Zhao 2023-05-24 09:33:29 +08:00 committed by Qt Cherry-pick Bot
parent f74bb1692c
commit bdea1751a3

View File

@ -535,15 +535,13 @@ scrolling range.
QSize QAbstractScrollArea::maximumViewportSize() const QSize QAbstractScrollArea::maximumViewportSize() const
{ {
Q_D(const QAbstractScrollArea); Q_D(const QAbstractScrollArea);
int hsbExt = d->hbar->sizeHint().height();
int vsbExt = d->vbar->sizeHint().width();
int f = 2 * d->frameWidth; int f = 2 * d->frameWidth;
QSize max = size() - QSize(f + d->left + d->right, f + d->top + d->bottom); QSize max = size() - QSize(f + d->left + d->right, f + d->top + d->bottom);
// Count the sizeHint of the bar only if it is displayed.
if (d->vbarpolicy == Qt::ScrollBarAlwaysOn) if (d->vbarpolicy == Qt::ScrollBarAlwaysOn)
max.rwidth() -= vsbExt; max.rwidth() -= d->vbar->sizeHint().width();
if (d->hbarpolicy == Qt::ScrollBarAlwaysOn) if (d->hbarpolicy == Qt::ScrollBarAlwaysOn)
max.rheight() -= hsbExt; max.rheight() -= d->hbar->sizeHint().height();
return max; return max;
} }