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
11The \l {Qt Quick} module provides support for the most common types of user
12input, including mouse and touch events, text input, and key-press events.
13Other modules provide support for other types of user input.
14
15This article covers how to handle basic user input. For information about
16audio-visual input, see the \l {qtmultimedia-index.html}{Qt Multimedia}
17documentation.
18
19\section2 Mouse and touch events
20
21The \l{Input Handlers}{input handlers} let QML applications handle mouse and
22touch 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.
24The \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
30scrolling.
31
32\section2 Keyboard and button events
33
34Button and key presses, from buttons on a device, a keypad, or a keyboard, can
35all be handled using the \l Keys attached property. This attached property is
36available on all \l Item derived types, and works with the \l Item::focus
37property to determine which type receives the key event. For simple key
38handling, you can set the focus to true on a single \l Item and do all your key
39handling there.
40
41\snippet qmlapp/usecases/userinput-keys.qml 0
42
43For text input, we have several QML types to choose from. TextInput provides an
44unstyled single-line editable text, while TextField is more suitable for
45form fields in applications. TextEdit can handle multi-line editable text,
46but TextArea is a better alternative as it adds styling.
47
48The following snippet demonstrates how to use these types in your application:
49
50\snippet qmlapp/usecases/userinput-text.qml 0
51*/