aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-26 20:27:16 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-28 10:17:20 +0000
commit929fd7b919fb873750f97f3e74b0986ce7c4e022 (patch)
treeb951dd19708fa6a92aea3259d3d30ed154e077f1 /src
parenta7e39a28575dc3421970e007b78731b614da258a (diff)
Scrollers: give control over layouting if parent != flickable
This allows utilizing the convenient attached properties of ScrollBar and ScrollIndicator, but positioning the scrollers outside of a clipping Flickable. Change-Id: I46fe79110658f4797469d042c56f51548eef6c70 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickscrollbar.cpp33
-rw-r--r--src/quicktemplates2/qquickscrollindicator.cpp33
2 files changed, 60 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp
index 69cac6ee..d3a2355c 100644
--- a/src/quicktemplates2/qquickscrollbar.cpp
+++ b/src/quicktemplates2/qquickscrollbar.cpp
@@ -65,9 +65,9 @@ QT_BEGIN_NAMESPACE
}
\endcode
- \note When ScrollBar is attached \l {ScrollBar::vertical}{vertically} or
- \l {ScrollBar::horizontal}{horizontally} to a Flickable, its geometry and
- the following properties are automatically set and updated as appropriate:
+ When ScrollBar is attached \l {ScrollBar::vertical}{vertically} or
+ \l {ScrollBar::horizontal}{horizontally} to a Flickable, the following
+ properties are automatically set and updated as appropriate:
\list
\li \l orientation
\li \l position
@@ -75,6 +75,29 @@ QT_BEGIN_NAMESPACE
\li \l active
\endlist
+ An attached ScrollBar re-parents itself to the target Flickable. A vertically
+ attached ScrollBar resizes itself to the height of the Flickable, and positions
+ itself to either side of it based on the \l {Control::mirrored}{layout direction}.
+ A horizontally attached ScrollBar resizes itself to the width of the Flickable,
+ and positions itself to the bottom. The automatic geometry management can be disabled
+ by specifying another parent for the attached ScrollBar. This can be useful, for
+ example, if the ScrollBar should be placed outside a clipping Flickable. This is
+ demonstrated by the following example:
+
+ \code
+ Flickable {
+ id: flickable
+ clip: true
+ // ...
+ ScrollBar.vertical: ScrollBar {
+ parent: flickable.parent
+ anchors.top: flickable.top
+ anchors.left: flickable.right
+ anchors.bottom: flickable.bottom
+ }
+ }
+ \endcode
+
Notice that ScrollBar does not filter key events of the Flickable it is
attached to. The following example illustrates how to implement scrolling
with up and down keys:
@@ -465,6 +488,8 @@ void QQuickScrollBarAttachedPrivate::mirrorVertical()
void QQuickScrollBarAttachedPrivate::layoutHorizontal(bool move)
{
Q_ASSERT(horizontal && flickable);
+ if (horizontal->parentItem() != flickable)
+ return;
horizontal->setWidth(flickable->width());
if (move)
horizontal->setY(flickable->height() - horizontal->height());
@@ -473,6 +498,8 @@ void QQuickScrollBarAttachedPrivate::layoutHorizontal(bool move)
void QQuickScrollBarAttachedPrivate::layoutVertical(bool move)
{
Q_ASSERT(vertical && flickable);
+ if (vertical->parentItem() != flickable)
+ return;
vertical->setHeight(flickable->height());
if (move)
vertical->setX(vertical->isMirrored() ? 0 : flickable->width() - vertical->width());
diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp
index 48adda0a..91d03ec9 100644
--- a/src/quicktemplates2/qquickscrollindicator.cpp
+++ b/src/quicktemplates2/qquickscrollindicator.cpp
@@ -65,9 +65,9 @@ QT_BEGIN_NAMESPACE
}
\endcode
- \note When ScrollIndicator is attached \l {ScrollIndicator::vertical}{vertically}
- or \l {ScrollIndicator::horizontal}{horizontally} to a Flickable, its geometry and
- the following properties are automatically set and updated as appropriate:
+ When ScrollIndicator is attached \l {ScrollIndicator::vertical}{vertically} or
+ \l {ScrollIndicator::horizontal}{horizontally} to a Flickable, the following
+ properties are automatically set and updated as appropriate:
\list
\li \l orientation
\li \l position
@@ -75,6 +75,29 @@ QT_BEGIN_NAMESPACE
\li \l active
\endlist
+ An attached ScrollIndicator re-parents itself to the target Flickable. A vertically
+ attached ScrollIndicator resizes itself to the height of the Flickable, and positions
+ itself to either side of it based on the \l {Control::mirrored}{layout direction}.
+ A horizontally attached ScrollIndicator resizes itself to the width of the Flickable,
+ and positions itself to the bottom. The automatic geometry management can be disabled
+ by specifying another parent for the attached ScrollIndicator. This can be useful, for
+ example, if the ScrollIndicator should be placed outside a clipping Flickable. This is
+ demonstrated by the following example:
+
+ \code
+ Flickable {
+ id: flickable
+ clip: true
+ // ...
+ ScrollIndicator.vertical: ScrollIndicator {
+ parent: flickable.parent
+ anchors.top: flickable.top
+ anchors.left: flickable.right
+ anchors.bottom: flickable.bottom
+ }
+ }
+ \endcode
+
Horizontal and vertical scroll indicators do not share the \l active state with
each other by default. In order to keep both indicators visible whilst scrolling
to either direction, establish a two-way binding between the active states as
@@ -268,6 +291,8 @@ void QQuickScrollIndicatorAttachedPrivate::activateVertical()
void QQuickScrollIndicatorAttachedPrivate::layoutHorizontal(bool move)
{
Q_ASSERT(horizontal && flickable);
+ if (horizontal->parentItem() != flickable)
+ return;
horizontal->setWidth(flickable->width());
if (move)
horizontal->setY(flickable->height() - horizontal->height());
@@ -276,6 +301,8 @@ void QQuickScrollIndicatorAttachedPrivate::layoutHorizontal(bool move)
void QQuickScrollIndicatorAttachedPrivate::layoutVertical(bool move)
{
Q_ASSERT(vertical && flickable);
+ if (vertical->parentItem() != flickable)
+ return;
vertical->setHeight(flickable->height());
if (move && !QQuickItemPrivate::get(vertical)->isMirrored())
vertical->setX(flickable->width() - vertical->width());