summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-10-13 21:32:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-14 20:47:17 +0000
commitc46e2e087e29016aec143ef83c72743d76e1501b (patch)
tree480ae46f4544d7b138fda28c10a9ec6e6681ecf6 /examples/widgets
parent3752ced2cabd5bdb576b6bb1c5c1ddced6af6be5 (diff)
Use QScroller in the Dir View example
We have never had enough examples that show how easy it is to install a QScroller. In this case, one line makes a QTreeView flickable. Task-number: QTBUG-86090 Change-Id: Idb8b4709617befb261f3b78d63ddbdaf5ad18d6b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit b0cd3bcec4317ed859ea13b3a2b33742c6ccecfe) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/src/dirview.qdoc10
-rw-r--r--examples/widgets/itemviews/dirview/main.cpp6
2 files changed, 13 insertions, 3 deletions
diff --git a/examples/widgets/doc/src/dirview.qdoc b/examples/widgets/doc/src/dirview.qdoc
index 6db339eced..d8c68bf41e 100644
--- a/examples/widgets/doc/src/dirview.qdoc
+++ b/examples/widgets/doc/src/dirview.qdoc
@@ -29,7 +29,7 @@
\example itemviews/dirview
\title Dir View Example
\ingroup examples-itemviews
- \brief This example demonstrates the usage of a tree view.
+ \brief This example demonstrates the usage of a tree view, and smooth flicking on a touchscreen.
The Dir View example shows a tree view of the local file
system. It uses the QFileSystemModel class to provide file
@@ -60,8 +60,14 @@
QTreeView object \c tree visualizes the filesystem in a tree structure.
\skipto tree.setAnimated(false)
- \printuntil tree.setWindowTitle
+ \printuntil tree.setColumnWidth
Sets layout options for animation, indentation, sorting, and sizing of the
filesystem tree.
+
+ \skipto QScroller::grabGesture
+ \printuntil QScroller::grabGesture
+
+ Creates a \l QScroller instance to recognize gestures on touchscreens,
+ so that you can flick the tree view with your finger.
*/
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp
index fcdf4c7ba4..20e5d45c95 100644
--- a/examples/widgets/itemviews/dirview/main.cpp
+++ b/examples/widgets/itemviews/dirview/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -52,6 +52,7 @@
#include <QFileSystemModel>
#include <QFileIconProvider>
#include <QScreen>
+#include <QScroller>
#include <QTreeView>
#include <QCommandLineParser>
#include <QCommandLineOption>
@@ -96,6 +97,9 @@ int main(int argc, char *argv[])
tree.resize(availableSize / 2);
tree.setColumnWidth(0, tree.width() / 3);
+ // Make it flickable on touchscreens
+ QScroller::grabGesture(&tree, QScroller::TouchGesture);
+
tree.setWindowTitle(QObject::tr("Dir View"));
tree.show();