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>
Pick-to: 6.5
Change-Id: Idaf9404860d1f778d7a89b19d9f7fc16201ce29e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Yuhang Zhao 2023-05-24 09:33:29 +08:00 committed by Yuhang Zhao
parent f7511171ac
commit 68f35a571a

View File

@ -535,15 +535,13 @@ scrolling range.
QSize QAbstractScrollArea::maximumViewportSize() const
{
Q_D(const QAbstractScrollArea);
int hsbExt = d->hbar->sizeHint().height();
int vsbExt = d->vbar->sizeHint().width();
int f = 2 * d->frameWidth;
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)
max.rwidth() -= vsbExt;
max.rwidth() -= d->vbar->sizeHint().width();
if (d->hbarpolicy == Qt::ScrollBarAlwaysOn)
max.rheight() -= hsbExt;
max.rheight() -= d->hbar->sizeHint().height();
return max;
}