diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-11-22 11:21:57 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-11-27 09:50:19 +0000 |
commit | 343cea9b49d7afa7614aea27aed7c48ef9c5be2e (patch) | |
tree | 6d028cbd7ba1fbd1e015579964b37364b4f4f5fb /src/quicktemplates2/qquickscrollview.cpp | |
parent | 8317e62c3e2381e6287c9a7e861d20f78aaea03f (diff) |
QQuickScrollView: override getContentWidth/Height()
A ScrollView lets you add the Flickable that should be decorated as
a child. If that flickable has one (and only one) child, the
contentWidth/Height properties of the ScrollView will be calculated
by using the implicit size of that child (unless you assign something
else to those properties explicitly).
This logic goes wrong when the flickable is a TableView for several
reasons. The first is that TableView will populate the content item
dynamically, and for the first delegate item added, the content size
of the ScrollView will be set to be the size of this item (since the
TableView only got one child at that point). The second is that
TableView has its own set of contentWidth/Height properties. And those
properties are not respected by ScrollView. So even if TableView set
the contentWidth/Height to be the size of the table, this will not
be used by ScrollView. The result is that ScrollView concludes that
the content item is empty, which means that no scrollbars end up
visible or usable.
This patch will fix this by overriding getContentWidth()/Height()
from QQuickPane. The implementation will check if the flickable
has valid contentWidth/Height values set, and if so, use
them. Otherwise it will fall back to the old QQuickPane implementation
(which will inspect the children etc).
Fixes: QTBUG-71974
Change-Id: I027b9b939a10df2aeb816dea596adcb452f914b9
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickscrollview.cpp')
-rw-r--r-- | src/quicktemplates2/qquickscrollview.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index abd75d311e..57b0177e48 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -132,6 +132,9 @@ public: void updateContentWidth(); void updateContentHeight(); + qreal getContentWidth() const override; + qreal getContentHeight() const override; + QQuickScrollBar *verticalScrollBar() const; QQuickScrollBar *horizontalScrollBar() const; @@ -249,6 +252,28 @@ void QQuickScrollViewPrivate::updateContentHeight() emit q->implicitContentHeightChanged(); } +qreal QQuickScrollViewPrivate::getContentWidth() const +{ + if (flickable) { + const qreal cw = flickable->contentWidth(); + if (cw > 0) + return cw; + } + + return QQuickPanePrivate::getContentWidth(); +} + +qreal QQuickScrollViewPrivate::getContentHeight() const +{ + if (flickable) { + const qreal ch = flickable->contentHeight(); + if (ch > 0) + return ch; + } + + return QQuickPanePrivate::getContentHeight(); +} + QQuickScrollBar *QQuickScrollViewPrivate::verticalScrollBar() const { Q_Q(const QQuickScrollView); |