summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qabstractscrollarea.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-07-29 21:31:57 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-10-04 09:48:40 +0000
commit3e59a88e8968c6cdac788926bec34c259146b6a8 (patch)
tree413741ca47e7d7bdf8d40e1b4fc7cbeb0ba9a9d0 /src/widgets/widgets/qabstractscrollarea.cpp
parent80cc6bcec4b204e50d1f2c7460a0b91c7d9ea6f9 (diff)
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 <samuel.gaist@idiap.ch> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/widgets/qabstractscrollarea.cpp')
-rw-r--r--src/widgets/widgets/qabstractscrollarea.cpp6
1 files changed, 4 insertions, 2 deletions
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;