Under Qt 5.12.11, the bug does not exist. So I took a look at the QAbstractScrollArea::sizeHint code of this version and compared it with the implementation used in recent versions of Qt and found that setting verticalScrollBarPolicy to "ScrollBarAlwaysOff" the "AdjustToContents" adjustment policy works. The default value was "ScrollBarAsNeeded", in fact we can see that this value is not handled but since in Qt 5.12.11 we only compare the vertical|horizontal]scrollBarPolicy to Qt::ScrollBarAlwaysOn it prevents this bug from appearing.
The version used in the Qt github master branch :
QSize QAbstractScrollArea::sizeHint() const
{
Q_D(const QAbstractScrollArea);
if (d->sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
return QSize(256, 192);
if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents) {
const int f = 2 * d->frameWidth;
const QSize frame( f, f );
const bool vbarHidden = d->vbar->isHidden() || d->vbarpolicy == Qt::ScrollBarAlwaysOff;
const bool hbarHidden = d->hbar->isHidden() || d->hbarpolicy == Qt::ScrollBarAlwaysOff;
const QSize scrollbars(vbarHidden ? 0 : d->vbar->sizeHint().width(),
hbarHidden ? 0 : d->hbar->sizeHint().height());
d->sizeHint = frame + scrollbars + viewportSizeHint();
}
return d->sizeHint;
}
The version used in Qt 5.12.11 :
QSize QAbstractScrollArea::sizeHint() const
{
Q_D(const QAbstractScrollArea);
if (d->sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
return QSize(256, 192);
if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents) {
const int f = 2 * d->frameWidth;
const QSize frame( f, f );
const QSize scrollbars(d->vbarpolicy == Qt::ScrollBarAlwaysOn ? d->vbar->sizeHint().width() : 0,
d->hbarpolicy == Qt::ScrollBarAlwaysOn ? d->hbar->sizeHint().height() : 0);
d->sizeHint = frame + scrollbars + viewportSizeHint();
}
return d->sizeHint;
}
Can someone update the status of this ticket : https://bugreports.qt.io/browse/QTBUG-101874
in any case, this method must be rewritten and it may not be obvious to handle the "ScrollBarAsNeeded" case at first glance