aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/src/appdevguide/usecases/userinput.qdoc
blob: 8425ad54ecd89c2434b8e6af0afff8e6b9c08fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page qtquick-usecase-userinput.html
\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

The \l QtQuick 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 QtSensors 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 QtSensors documentation. For
information about audio-visual input, please see the \l QtMultimedia documentation.

\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.

\snippet qml/usecases/userinput.qml 0

For more advanced use cases requiring multiple touch points, please read the
documentation for the \l MultiPointTouchArea element and the \l PinchArea element.

Note that some elements 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.

\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
is available on all \l Item derived elements, and works with the \l Item::focus property
to determine which element receives the key event. For simple key handling, you can set the focus
to true on a single \l Item and do all your key handling there.

\snippet qml/usecases/userinput-keys.qml 0

For text input the \l QtQuick 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.

Here is all you need to get a working TextInput:

\code
import QtQuick 2.0

TextInput {
    focus: true
    text: "Initial Text"
}
\endcode

*/