summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVenugopal Shivashankar <Venugopal.Shivashankar@qt.io>2018-09-20 09:16:57 +0200
committerVenugopal Shivashankar <Venugopal.Shivashankar@qt.io>2018-09-25 09:58:04 +0000
commitfe91a75b3eb615b74fd28a5c6ad403020005264b (patch)
treeae3b588845882004a07db60ef3bf3e9e38ecd3ec
parent462fa235d4b799c12f664e9f6d8c0821d09bdc62 (diff)
downloadqtdoc-fe91a75b3eb615b74fd28a5c6ad403020005264b.tar.gz
Doc: Highlight Controls 2 and Input handler types for user input
In addition, updated a snippet file and added another to complement the text. Task-number: QTBUG-70333 Change-Id: I20e8e13390a00151d040f92d7a54c661e64c17e3 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--doc/snippets/qmlapp/usecases/userinput-text.qml92
-rw-r--r--doc/snippets/qmlapp/usecases/userinput.qml7
-rw-r--r--doc/src/qmlapp/usecases/userinput.qdoc53
3 files changed, 119 insertions, 33 deletions
diff --git a/doc/snippets/qmlapp/usecases/userinput-text.qml b/doc/snippets/qmlapp/usecases/userinput-text.qml
new file mode 100644
index 00000000..355f99e1
--- /dev/null
+++ b/doc/snippets/qmlapp/usecases/userinput-text.qml
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//![0]
+import QtQuick 2.12
+import QtQuick.Controls 2.4
+import QtQuick.Layouts 1.3
+
+ApplicationWindow {
+ width: 300
+ height: 200
+ visible: true
+
+ ColumnLayout {
+ anchors.fill: parent
+ TextField {
+ id: singleline
+ text: "Initial Text"
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
+ Layout.margins: 5
+ background: Rectangle {
+ implicitWidth: 200
+ implicitHeight: 40
+ border.color: singleline.focus ? "#21be2b" : "lightgray"
+ color: singleline.focus ? "lightgray" : "transparent"
+ }
+ }
+
+ TextArea {
+ id: multiline
+ placeholderText: "Initial text\n...\n...\n"
+ Layout.alignment: Qt.AlignLeft
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.margins: 5
+ background: Rectangle {
+ implicitWidth: 200
+ implicitHeight: 100
+ border.color: multiline.focus ? "#21be2b" : "lightgray"
+ color: multiline.focus ? "lightgray" : "transparent"
+ }
+ }
+ }
+}
+//![0]
diff --git a/doc/snippets/qmlapp/usecases/userinput.qml b/doc/snippets/qmlapp/usecases/userinput.qml
index daa50d4f..23ac0bbe 100644
--- a/doc/snippets/qmlapp/usecases/userinput.qml
+++ b/doc/snippets/qmlapp/usecases/userinput.qml
@@ -49,7 +49,7 @@
****************************************************************************/
//![0]
-import QtQuick 2.3
+import QtQuick 2.12
Item {
id: root
@@ -71,9 +71,8 @@ Item {
height: 120
color: "red"
- MouseArea {
- anchors.fill: parent
- onClicked: rectangle.width += 10
+ TapHandler {
+ onTapped: rectangle.width += 10
}
}
}
diff --git a/doc/src/qmlapp/usecases/userinput.qdoc b/doc/src/qmlapp/usecases/userinput.qdoc
index d8e066ae..1ffbe6b8 100644
--- a/doc/src/qmlapp/usecases/userinput.qdoc
+++ b/doc/src/qmlapp/usecases/userinput.qdoc
@@ -29,33 +29,35 @@
\title Use Case - Responding To User Input in QML
\brief Example of how to accept user input and respond to it in a QML application
-\section1 Supported Types of User Input
+\section1 Supported types of user input
The \l {Qt Quick} module provides support for the most common types of user input,
-including mouse and touch events, text input and key-press events. Other
-modules provide support for other types of user input (for example, the
-\l {Qt Sensors} module provides support for shake-gestures in QML applications).
+including mouse and touch events, text input, and key-press events. Other
+modules provide support for other types of user input for example, the
+\l {Qt Sensors} module provides support for shake-gestures in QML applications.
This article covers how to handle basic user input; for further information
-about motion-gesture support, please see the \l {Qt Sensors} documentation. For
-information about audio-visual input, please see the \l {Qt Multimedia} documentation.
+about motion-gesture support, see the \l {Qt Sensors} documentation. For
+information about audio-visual input, see the \l {Qt Multimedia} documentation.
-\section2 Mouse and Touch Events
+\section2 Mouse and touch events
-The \l MouseArea type allows mouse and touch events to be handled in a QML
-application. A \l MouseArea can be combined with either an \l Image or a
-\l Rectangle and \l Text object to implement a simple button.
+The \l{Input Handlers}{input handlers} let QML applications handle mouse and
+touch events. For example, you could create a button by adding a
+\l TapHandler to an Image, or to a \l Rectangle with a \l Text object inside.
+The \l TapHandler responds to taps or clicks on any type of pointing device.
\snippet qmlapp/usecases/userinput.qml 0
-For more advanced use cases requiring multiple touch points, please read the
-documentation for the \l MultiPointTouchArea type and the \l PinchArea type.
+For more advanced use cases such as, drag, pinch and zoom gestures, see
+documentation for the \l DragHandler and \l PinchHandler types.
-Note that some types have their own built in input handling. For example,
-\l Flickable responds to mouse dragging, mouse wheel scrolling, touch dragging,
-and touch flicking by default.
+\note Some types have their own built-in input handling. For example,
+\l Flickable responds to mouse dragging and mouse wheel scrolling. It handles
+touch dragging and flicking via synthetic mouse events that are created when
+the touch events are not handled.
-\section2 Keyboard and Button Events
+\section2 Keyboard and button events
Button and key presses, from buttons on a device, a keypad, or a keyboard,
can all be handled using the \l Keys attached property. This attached property
@@ -65,19 +67,12 @@ to true on a single \l Item and do all your key handling there.
\snippet qmlapp/usecases/userinput-keys.qml 0
-For text input the \l {Qt Quick} module provides several built-in types.
-In particular, the \l TextInput and \l TextEdit types allow for single-line
-entry and multi-line editing respectively.
+For text input, we have several QML types to choose from. TextInput provides an
+unstyled single-line editable text, while TextField is more suitable for
+form fields in applications. TextEdit can handle multi-line editable text,
+but TextArea is a better alternative as it adds styling.
-Here is all you need to get a working TextInput:
-
-\code
-import QtQuick 2.3
-
-TextInput {
- focus: true
- text: "Initial Text"
-}
-\endcode
+The following snippet demonstrates how to use these types in your application:
+\snippet qmlapp/usecases/userinput-text.qml 0
*/