AppTextField

A single-line TextField input control. More...

Import Statement: import VPlayApps 1.0
Since: V-Play 2.7.0
Inherits:

TextField

Properties

Detailed Description

AppTextField is an extension of the basic QML TextField for getting single-line text input from the user.

It implements a default TextFieldStyle to add platform-specific styling.

How do I set a placeholder for the text field?

Input controls like AppTextInput or AppTextField, which extends the QML TextField type, own a placeholderText property, which you can use for your placeholder text.

 import VPlayApps 1.0
 import QtQuick 2.0

 App {
   Page {

     // remove focus from textedit if background is clicked
     MouseArea {
       anchors.fill: parent
       onClicked: textEdit.focus = false
     }

     // background for input
     Rectangle {
       anchors.fill: textEdit
       anchors.margins: -dp(8)
       color: "lightgrey"
     }

     // input
     AppTextField {
       id: textEdit
       width: dp(200)
       placeholderText: "What's your name?"
       anchors.centerIn: parent
     }
   }
 }

How do I show validation errors?

The text input components provide predefined validators that you can use, they are called inputMethodHints.

You can also add custom validators to restrict the accepted input to a certain input type or expression. Input that does not match the validator is not accepted. To do custom validations and show errors for accepted input, you can add simple checks and control the visibility of errors with property bindings:

 import VPlayApps 1.0
 import QtQuick 2.0

 App {
   // background for input
   Rectangle {
     anchors.fill: textInput
     anchors.margins: -dp(8)
     color: "lightgrey"
   }

   // input
   AppTextField {
     id: textInput
     width: dp(200)
     placeholderText: "What's your name?"
     anchors.centerIn: parent

     // only allow letters and check length
     validator: RegExpValidator {
       regExp: /[A-Za-z]+/
     }
     property bool isTooLong: textInput.text.length >= 6
   }

   // show error if too long
   AppText {
     text: "Error: Use less than 6 letters."
     color: "red"
     anchors.top: textInput.bottom
     anchors.topMargin: dp(16)
     anchors.left: textInput.left
     visible: textInput.isTooLong
   }
 }

More Frequently Asked Development Questions

Find more examples for frequently asked development questions and important concepts in the following guides:

Property Documentation

backgroundColor : color

The background color of the text field. If the background is transparent and the text field's borderWidth is 0, the control uses a native look on Android.

The default value for Android is transparent, otherwise it is Theme::backgroundColor.


borderColor : color

The color of the text field's border.

The default value is Theme::dividerColor.


borderWidth : real

The width of the text field's border. If the text field has no border and the backgroundColor is transparent, the control uses a native look on Android.

The default value is 0.


bottomPadding : real

The bottom padding of the text within the AppTextField.

This QML property was introduced in V-Play 2.17.1.


clearsOnBeginEditing : bool

If set to true, the text field's current text is cleared when the user selects the text field to begin editing. If false, the text field places an insertion point at the place where the user tapped the field.

The default value is false.

This QML property was introduced in V-Play 2.7.0.


cursorColor : color

The color of the cursor that marks the current position in the text field. Matches Theme::inputCursorColor by default.

This QML property was introduced in V-Play 2.7.0.


leftPadding : real

The left padding of the text within the AppTextField.

This QML property was introduced in V-Play 2.17.1.


placeholderColor : color

The color for the placeholder text that is displayed when the field is empty.

The default value is Theme::placeholderTextColor.


radius : real

The Rectangle::radius of the background.

The default value is 0.


rightPadding : real

The right padding of the text within the AppTextField.

This QML property was introduced in V-Play 2.17.1.


selectionColor : color

The color of selected text in the text field. Matches Theme::inputSelectionColor by default.

This QML property was introduced in V-Play 2.7.0.


showClearButton : bool

If set to true, a clear button is displayed at the right side of the text field as soon as the text field has contents, as a way for the user to remove the current text.

The default value is false.

This QML property was introduced in V-Play 2.7.0.


topPadding : real

The top padding of the text within the AppTextField.

This QML property was introduced in V-Play 2.17.1.


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support