O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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+/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required