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\meta {keywords} {qmltopic}
6\title Handling user input
7\keyword Use Case - Responding To User Input in QML
8\brief Example of how to accept user input and respond to it in a QML application
9
10\section1 Supported types of user input
11
12The \l {Qt Quick} module provides support for the most common types of user
13input, including mouse and touch events, text input, and key-press events.
14Other modules provide support for other types of user input.
15
16This article covers how to handle basic user input. For information about
17audio-visual input, see the \l {qtmultimedia-index.html}{Qt Multimedia}
18documentation.
19
20\section2 Mouse and touch events
21
22The \l{Input Handlers}{input handlers} let QML applications handle mouse and
23touch events. For example, you could create a button by adding a
24\l TapHandler to an Image, or to a \l Rectangle with a \l Text object inside.
25The \l TapHandler responds to taps or clicks on any type of pointing device.
26
27\snippet qmlapp/usecases/userinput.qml 0
28
29\note Some Item types have their own built-in input handling. For example,
30\l Flickable responds to mouse dragging, touch flicking, and mouse wheel
31scrolling.
32
33\section2 Keyboard and button events
34
35Button and key presses, from buttons on a device, a keypad, or a keyboard, can
36all be handled using the \l Keys attached property. This attached property is
37available on all \l Item derived types, and works with the \l Item::focus
38property to determine which type receives the key event. For simple key
39handling, you can set the focus to true on a single \l Item and do all your key
40handling there.
41
42\snippet qmlapp/usecases/userinput-keys.qml 0
43
44For text input, we have several QML types to choose from. TextInput provides an
45unstyled single-line editable text, while TextField is more suitable for
46form fields in applications. TextEdit can handle multi-line editable text,
47but TextArea is a better alternative as it adds styling.
48
49The following snippet demonstrates how to use these types in your application:
50
51\snippet qmlapp/usecases/userinput-text.qml 0
52*/