diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-07-29 21:31:57 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-10-04 09:48:40 +0000 |
commit | 3e59a88e8968c6cdac788926bec34c259146b6a8 (patch) | |
tree | 413741ca47e7d7bdf8d40e1b4fc7cbeb0ba9a9d0 /src/widgets/itemviews | |
parent | 80cc6bcec4b204e50d1f2c7460a0b91c7d9ea6f9 (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/itemviews')
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 6 |
2 files changed, 1 insertions, 7 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index e7edd08d2a..32bbef07e9 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1111,8 +1111,6 @@ QSize QTableView::viewportSizeHint() const Q_D(const QTableView); QSize result( (d->verticalHeader->isHidden() ? 0 : d->verticalHeader->width()) + d->horizontalHeader->length(), (d->horizontalHeader->isHidden() ? 0 : d->horizontalHeader->height()) + d->verticalHeader->length()); - result += QSize(verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0, - horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0); return result; } diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 920e3b346b..2be126ebc6 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -2686,11 +2686,7 @@ QSize QTreeView::viewportSizeHint() const QSize result = QSize(d->header->length(), deepestRect.bottom() + 1); // add size for header - result += QSize(0, d->header->isVisible() ? d->header->height() : 0); - - // add size for scrollbars - result += QSize(verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0, - horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0); + result += QSize(0, d->header->isHidden() ? 0 : d->header->height()); return result; } |