diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-10-13 16:27:13 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-10-14 13:38:22 +0200 |
commit | 0a48787cef9c37a4607f2158abebaa23cbf9ea59 (patch) | |
tree | 0cecd7ace70295b099f1a6d8d46101714601e703 /src | |
parent | ea96b511924399c6fd4e5bcb6a1f14f89c117a4a (diff) |
ScrollView: always clip implicitly created Flickable
We almost always want to clip the flickable so that flickable
contents doesn't show up outside the scrollview. The only time
this is not really needed, is when the scrollview covers the whole
window and the scrollbars are transient. But for that corner case, if
this optimization is needed, the user can simply create his own flickable
child inside the scrollview, and control clipping on it explicit.
[ChangeLog][ScrollView] ScrollView now clips its contents by default.
Change-Id: I44bd7a8c397b90e14d0b9d5db8ec6523da205648
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/doc/snippets/qtquickcontrols2-scrollview.qml | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickscrollview.cpp | 19 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-scrollview.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollview.qml index dce07b39..c96ae1ed 100644 --- a/src/imports/controls/doc/snippets/qtquickcontrols2-scrollview.qml +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollview.qml @@ -50,7 +50,6 @@ Rectangle { ScrollView { width: 200 height: 200 - clip: true Label { text: "ABC" diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index f9f4c9f8..f295ee30 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -61,15 +61,16 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-scrollview.qml file - \note ScrollView does not automatically clip its contents. If it is not used as - a full-screen item, you should consider setting the \l {Item::}{clip} property - to \c true, as shown above. - The second example illustrates using an existing \l Flickable, that is, a \l ListView. \snippet qtquickcontrols2-scrollview-listview.qml file + \note As of Qt-6.0, ScrollView automatically clips its contents if you + don't use a Flickable as a child. If this is not wanted, you can + set your own Flickable as a child, and control the \l {Item::}{clip} + property on the Flickable explicitly. + \section2 Sizing As with Flickable, there are several things to keep in mind when using @@ -180,7 +181,15 @@ QQuickFlickable *QQuickScrollViewPrivate::ensureFlickable(bool content) if (!flickable) { flickableHasExplicitContentWidth = false; flickableHasExplicitContentHeight = false; - setFlickable(new QQuickFlickable(q), content); + auto flickable = new QQuickFlickable(q); + // We almost always want to clip the flickable so that flickable + // contents doesn't show up outside the scrollview. The only time + // this is not really needed, is when the scrollview covers the whole + // window and the scrollbars are transient. But for that corner case, if this + // optimization is needed, the user can simply create his own flickable + // child inside the scrollview, and control clipping on it explicit. + flickable->setClip(true); + setFlickable(flickable, content); } return flickable; } |