Text input fields

Apart from the attached properties we described, Qt Quick provides built-in elements for handling keyboard input. The two most basic types are TextInput and TextEdit, which are QML equivalents of QLineEdit and QTextEdit. The former are used for single-line text input, while the latter serves as its multiline counterpart. They both offer cursor handling, undo-redo functionality, and text selections. You can validate text typed into TextInput by assigning a validator to the validator property. For example, to obtain an item where the user can input a dot-separated IP address, we can use the following declaration:

TextInput { id: ipAddress width: 100 validator: RegExpValidator { // four numbers separated by dots regExp: /\d+\.\d+\.\d+\.\d+/ ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.