From 3e59a88e8968c6cdac788926bec34c259146b6a8 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 29 Jul 2018 21:31:57 +0200 Subject: QAbstractScrollArea: fix sizeHint when widget is not visible QTable/QTreeView did not follow the documentation and returned their needed size with scrollbars within viewportSizeHint(). Then sizeHint() also took the size of the scrollbars into account when the policy was set to ScrollBarAlwaysOn. This lead to different results when the widget was shown/hidden and/or the scrollbar was visible or not. Fix it by only adding the additional size when the scrollbars are really visible. Also use header->isHidden() instead of isVisible() in QTreeView the same way it is done in QTableView. [ChangeLog][QtWidgets][QAbstractScrollArea] QTableView/QTreeView are now reporting their viewportSizeHint() correctly taking into account its scroll bars visibility and visibilityPolicy. Task-number: QTBUG-69120 Change-Id: If50959a9f7429275e3e33122644c978fb64972ba Reviewed-by: Samuel Gaist Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qabstractscrollarea.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets/qabstractscrollarea.cpp') diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 598d173144..fd5d7d8069 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -1604,8 +1604,10 @@ QSize QAbstractScrollArea::sizeHint() const 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); + 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; -- cgit v1.2.3