Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
userinput.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
/*!
4
\page qtquick-usecase-userinput.html
5
\title Handling user input
6
\keyword Use Case - Responding To User Input in QML
7
\brief Example of how to accept user input and respond to it in a QML application
8
9
\section1 Supported types of user input
10
11
The \l {Qt Quick} module provides support for the most common types of user
12
input, including mouse and touch events, text input, and key-press events.
13
Other modules provide support for other types of user input.
14
15
This article covers how to handle basic user input. For information about
16
audio-visual input, see the \l {qtmultimedia-index.html}{Qt Multimedia}
17
documentation.
18
19
\section2 Mouse and touch events
20
21
The \l{Input Handlers}{input handlers} let QML applications handle mouse and
22
touch events. For example, you could create a button by adding a
23
\l TapHandler to an Image, or to a \l Rectangle with a \l Text object inside.
24
The \l TapHandler responds to taps or clicks on any type of pointing device.
25
26
\snippet qmlapp/usecases/userinput.qml 0
27
28
\note Some Item types have their own built-in input handling. For example,
29
\l Flickable responds to mouse dragging, touch flicking, and mouse wheel
30
scrolling.
31
32
\section2 Keyboard and button events
33
34
Button and key presses, from buttons on a device, a keypad, or a keyboard, can
35
all be handled using the \l Keys attached property. This attached property is
36
available on all \l Item derived types, and works with the \l Item::focus
37
property to determine which type receives the key event. For simple key
38
handling, you can set the focus to true on a single \l Item and do all your key
39
handling there.
40
41
\snippet qmlapp/usecases/userinput-keys.qml 0
42
43
For text input, we have several QML types to choose from. TextInput provides an
44
unstyled single-line editable text, while TextField is more suitable for
45
form fields in applications. TextEdit can handle multi-line editable text,
46
but TextArea is a better alternative as it adds styling.
47
48
The following snippet demonstrates how to use these types in your application:
49
50
\snippet qmlapp/usecases/userinput-text.qml 0
51
*/
qtdeclarative
src
quick
doc
src
getting-started
userinput.qdoc
Generated on
for Qt by
1.14.0