From f14fa8b42c2d09afbc27209ffc520dfaf6dbc4d7 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 14 Feb 2019 14:49:05 +0100 Subject: QQuickScrollView: only forward content size to flickable if set explicit TableView monitors if the application sets an explicit contentWidth/Height, and skips calculating it when that is the case. So be more careful from ScrollView, and don't set it on the flickable if the application did not set it explicitly. By doing it this way, you can now set an explicit contentWidth/Height both in ScrollView and TableView, and it will be respected. Task-number: QTBUG-72536 Change-Id: Ib87fa6958881fccdc47f50133e996484392281b6 Reviewed-by: Shawn Rutledge Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickscrollview.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index 57b0177e..7890a30a 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -154,6 +154,7 @@ public: bool wasTouched = false; QQuickFlickable *flickable = nullptr; + bool ownsFlickable = false; }; QList QQuickScrollViewPrivate::contentChildItems() const @@ -174,8 +175,10 @@ QQuickItem *QQuickScrollViewPrivate::getContentItem() QQuickFlickable *QQuickScrollViewPrivate::ensureFlickable(bool content) { Q_Q(QQuickScrollView); - if (!flickable) + if (!flickable) { setFlickable(new QQuickFlickable(q), content); + ownsFlickable = true; + } return flickable; } @@ -563,8 +566,16 @@ void QQuickScrollView::contentSizeChange(const QSizeF &newSize, const QSizeF &ol Q_D(QQuickScrollView); QQuickPane::contentSizeChange(newSize, oldSize); if (d->flickable) { - d->flickable->setContentWidth(newSize.width()); - d->flickable->setContentHeight(newSize.height()); + // Only set the content size on the flickable if we created the + // flickable ourselves. Otherwise we can end up overwriting + // assignments done to those properties by the application. The + // exception is if the application has assigned a content size + // directly to the scrollview, which will then win even if the + // application has assigned something else to the flickable. + if (d->hasContentWidth || d->ownsFlickable) + d->flickable->setContentWidth(newSize.width()); + if (d->hasContentHeight || d->ownsFlickable) + d->flickable->setContentHeight(newSize.height()); } } -- cgit v1.2.3