Obsolete Members for TextField

The following members of QML type TextField are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.


Property Documentation

acceptableInput : bool

This property is always true unless a validator or input mask has been set. If a validator or input mask has been set, this property will only be true if the current text is acceptable to the validator or input mask as a final string (not as an intermediate string).

activeFocusOnPress : bool

Whether the TextField should gain active focus on a mouse press. By default this is set to true.

autoScroll : bool

Whether the TextField should scroll when the text is longer than the width. By default this is set to true.

canPaste : bool

Returns true if the TextField is writable and the content of the clipboard is suitable for pasting into the TextField.

canRedo : bool

Returns true if the TextField is writable and there are undone operations that can be redone.

canUndo : bool

Returns true if the TextField is writable and there are previous operations that can be undone.

color : color

The text color.

contentHeight : real

Returns the height of the text, including the height past the height that is covered if the text does not fit within the set height.

contentWidth : real

Returns the width of the text, including the width past the width which is covered due to insufficient wrapping if wrapMode is set.

cursorDelegate : Component

The delegate for the cursor in the TextField.

If you set a cursorDelegate for a TextField, this delegate will be used for drawing the cursor instead of the standard cursor. An instance of the delegate will be created and managed by the TextField when a cursor is needed, and the x property of delegate instance will be set so as to be one pixel before the top left of the current character.

Note that the root item of the delegate component must be a QQuickItem or QQuickItem derived item.

cursorPosition : int

The position of the cursor in the TextField.

cursorRectangle : rectangle

The rectangle where the standard text cursor is rendered within the text input. Read only.

The position and height of a custom cursorDelegate are updated to follow the cursorRectangle automatically when it changes. The width of the delegate is unaffected by changes in the cursor rectangle.

cursorVisible : bool

Set to true when the TextField shows a cursor.

This property is set and unset when the TextField gets active focus, so that other properties can be bound to whether the cursor is currently showing. As it gets set and unset automatically, when you set the value yourself you must keep in mind that your value may be overwritten.

It can be set directly in script, for example if a KeyProxy might forward keys to it and you desire it to look active when this happens (but without actually giving it active focus).

It should not be set directly on the item, like in the below QML, as the specified value will be overridden an lost on focus changes.

TextField {
    text: "Text"
    cursorVisible: false

In the above snippet the cursor will still become visible when the TextField gains active focus.

displayText : string

This is the text displayed in the TextField.

If echoMode is set to TextInput::Normal, this holds the same value as the text property. Otherwise, this property holds the text visible to the user, while the text property holds the actual entered text.

echoMode : enumeration

Specifies how the text should be displayed in the TextField.

  • - TextInput.Normal - Displays the text as it is. (Default)
  • - TextInput.Password - Displays asterixes instead of characters.
  • - TextInput.NoEcho - Displays nothing.
  • - TextInput.PasswordEchoOnEdit - Displays characters as they are entered while editing, otherwise displays asterisks.

effectiveHorizontalAlignment : enumeration

See horizontalAlignment for details.

errorHighlight : bool

Allows highlighting errors in the TextField.

font : font

Font used in the TextField.

hasClearButton : bool

Specifies whether the control has a clear button or not.

highlighted : bool

The property presents whether the TextField is highlighted or not. By default the TextField gets highlighted when gets the focus, so can accept text input. This property allows to control the highlight separately from the focused behavior.

horizontalAlignment : enumeration

Sets the horizontal alignment of the text within the item's width and height. By default, the text alignment follows the natural alignment of the text, for example text that is read from left to right will be aligned to the left.

TextField does not have vertical alignment, as the natural height is exactly the height of the single line of text. If you set the height manually to something larger, TextInput will always be top aligned vertically. You can use anchors to align it however you want within another item.

The valid values for horizontalAlignment are TextInput.AlignLeft, TextInput.AlignRight and TextInput.AlignHCenter.

Valid values for verticalAlignment are TextInput.AlignTop (default), TextInput.AlignBottom TextInput.AlignVCenter.

When using the attached property LayoutMirroring::enabled to mirror application layouts, the horizontal alignment of text will also be mirrored. However, the property horizontalAlignment will remain unchanged. To query the effective horizontal alignment of TextField, use the read-only property effectiveHorizontalAlignment.

inputMask : string

Allows you to set an input mask on the TextField, restricting the text inputs. See QLineEdit::inputMask for further details, as the exact same mask strings are used by TextField.

Note that when using an inputMask together with echoMode to hide the input the empty TextField may still show masked characters - consider validator instead.

See also acceptableInput and validator.

inputMethodComposing : bool

This property holds whether the TextInput has partial text input from an input method.

While it is composing an input method may rely on mouse or key events from the TextField to edit or commit the partial text. This property can be used to determine when to disable events handlers that may interfere with the correct operation of an input method.

inputMethodHints : enumeration

Provides hints to the input method about the expected content of the text input and how it should operate.

The value is a bit-wise combination of flags, or Qt.ImhNone if no hints are set.

Flags that alter behaviour are:

  • - Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords. This is automatically set when setting echoMode to TextInput.Password.
  • - Qt.ImhSensitiveData - Typed text should not be stored by the active input method in any persistent storage like predictive user dictionary.
  • - Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case when a sentence ends.
  • - Qt.ImhPreferNumbers - Numbers are preferred (but not required).
  • - Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).
  • - Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).
  • - Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.
  • - Qt.ImhDate - The text editor functions as a date field.
  • - Qt.ImhTime - The text editor functions as a time field.

Flags that restrict input (exclusive flags) are:

  • - Qt.ImhDigitsOnly - Only digits are allowed.
  • - Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign.
  • - Qt.ImhUppercaseOnly - Only upper case letter input is allowed.
  • - Qt.ImhLowercaseOnly - Only lower case letter input is allowed.
  • - Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed.
  • - Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed.
  • - Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed.


  • - Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.

length : int

Returns the total number of characters in the TextField item.

If the TextField has an inputMask the length will include mask characters and may differ from the length of the string returned by the text property.

This property can be faster than querying the length the text property as it doesn't require any copying or conversion of the TextField's internal string data.

maximumLength : int

The maximum permitted length of the text in the TextField.

If the text is too long, it is truncated at the limit.

By default, this property contains a value of 32767.

mouseSelectionMode : enumeration

Specifies how text should be selected using a mouse.

  • -TextInput.SelectCharacters - The selection is updated with individual characters. (Default)
  • -TextInput.SelectWords - The selection is updated with whole words.

This property only applies when selectByMouse is true.

passwordCharacter : string

This is the character displayed when echoMode is set to Password or PasswordEchoOnEdit. By default it is the unicode character 2022.

If this property is set to a string with more than one character, the first character is used. If the string is empty, the value is ignored and the property is not set.

persistentSelection : bool

Whether the TextField should keep its selection when it loses active focus to another item in the scene. By default this is set to false.

placeholderText : string

Text that appears when there is no content in the component.

popover : var

The property overrides the default popover of the TextField. When set, the TextField will open the given popover instead of the default one defined. The popover can either be a component or a URL to be loaded.

primaryItem : list<Object>

Overlaid component that can be set for the fore side of the TextField, e.g.showing a magnifier to implement search functionality.

readOnly : bool

Sets whether user input can modify the contents of the TextField.

If readOnly is set to true, then user input will not affect the text property. Any bindings or attempts to set the text property will still work.

renderType : enumeration

Override the default rendering type for this component.

Supported render types are:

  • - Text.QtRendering - (default)
  • - Text.NativeRendering

Select Text.NativeRendering if you prefer text to look native on the target platform and do not require advanced features such as transformation of the text. Using such features in combination with the NativeRendering render type will lend poor and sometimes pixelated results.

secondaryItem : list<Object>

Overlaid component that can be set for the rear side of the TextField, e.g.showing a CAPS LOCK or NUM LOCK indication. The overlaid components will be placed right after the clear button.

selectByMouse : bool

Defaults to true.

If false, the user cannot use the mouse to select text, only can use it to focus the input.

[read-only] selectedText : string

This read-only property provides the text currently selected in the text input.

It is equivalent to the following snippet, but is faster and easier to use.


selectedTextColor : color

The highlighted text color, used in selections.

selectionColor : color

The text highlight color, used behind selections.

selectionEnd : int

The cursor position after the last character in the current selection.

This property is read-only. To change the selection, use select(start,end), selectAll(), or selectWord().

selectionStart : int

The cursor position before the first character in the current selection.

This property is read-only. To change the selection, use select(start,end), selectAll(), or selectWord().

text : string

The text in the TextField.

validator : Validator

Allows you to set a validator on the TextInput. When a validator is set the TextField will only accept input which leaves the text property in an acceptable or intermediate state. The accepted signal will only be sent if the text is in an acceptable state when enter is pressed.

Currently supported validators are IntValidator, DoubleValidator and RegExpValidator. An example of using validators is shown below, which allows input of integers between 11 and 31 into the text input:

import QtQuick 2.4
import Lomiri.Components 1.3
    validator: IntValidator{bottom: 11; top: 31;}
    focus: true

The next example is for a use case of typing a PIN with masked characters.

import QtQuick 2.4
import Lomiri.Components 1.3

TextField {
    echoMode: TextInput.Password
    validator: RegExpValidator { regExp: /^\d{4}$/ }
    inputMethodHints: Qt.ImhDigitsOnly

See also acceptableInput and inputMask.

verticalAlignment : enumeration

See horizontalAlignment for details.