diff options
author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-01-30 07:42:51 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-31 16:29:43 +0200 |
commit | 28881c0c91aa53412fae32c52ab297c76e890971 (patch) | |
tree | 09f0b9daed6813e44f4abd4cf0da0dc165621e96 /src/widgets | |
parent | 99ef183cb1395bab34ec8865d1d47ffa44b94a64 (diff) |
Make QGraphicsView respect scrollbar policies
When calculating the maximum height / width which a QGraphicsView can display,
make sure we only take the scrollbars' dimensions into account if their policy
is set to Qt::ScrollBarAsNeeded:
- if the policy is set to Qt::ScrollBarAlwaysOff, the scrollbar will not be
displayed at all
- if the policy is set to Qt::ScrollBarAlwaysOn, the scrollbar's dimensions
have already been substracted from the available space by
QAbstractScrollArea::maximumViewportSize()
Task-number: QTBUG-14711
Change-Id: If5d24b41dbe7b089abca2bf61ccbd370d4de79a1
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index c2942212e6..7a63c1eaf4 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -381,19 +381,21 @@ void QGraphicsViewPrivate::recalculateContentSize() if (frameOnlyAround) scrollBarExtent += frameWidth * 2; - bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy != Qt::ScrollBarAlwaysOff; - bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy != Qt::ScrollBarAlwaysOff; - if (useHorizontalScrollBar && !useVerticalScrollBar) { + // We do not need to subtract the width scrollbars whose policy is + // Qt::ScrollBarAlwaysOn, this was already done by maximumViewportSize(). + bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy == Qt::ScrollBarAsNeeded; + bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy == Qt::ScrollBarAsNeeded; + if (useHorizontalScrollBar && vbarpolicy == Qt::ScrollBarAsNeeded) { if (viewRect.height() > height - scrollBarExtent) useVerticalScrollBar = true; } - if (useVerticalScrollBar && !useHorizontalScrollBar) { + if (useVerticalScrollBar && hbarpolicy == Qt::ScrollBarAsNeeded) { if (viewRect.width() > width - scrollBarExtent) useHorizontalScrollBar = true; } - if (useHorizontalScrollBar && hbarpolicy != Qt::ScrollBarAlwaysOn) + if (useHorizontalScrollBar) height -= scrollBarExtent; - if (useVerticalScrollBar && vbarpolicy != Qt::ScrollBarAlwaysOn) + if (useVerticalScrollBar) width -= scrollBarExtent; // Setting the ranges of these scroll bars can/will cause the values to |