Qt Reference Documentation

QML TextArea Element

Provides a component for editing and displaying both plain and rich text. More...

This element was introduced in Qt Quick Components 1.0.

Properties

Methods

Detailed Description

The TextArea component displays a block of editable and formatted text. It can display both plain and rich text. TextArea implements the horizontal and vertical scrolling. Scroll bars appear when the content is flicked, or on the focus gain if the content does not fit to view port. TextArea is a superset of TextEdit to implement the Symbian-style look-and-feel. The clipboard support is provided by the cut(), copy(), and paste() functions.

TextArea Basic Examples

The code examples below illustrate various features of TextArea.

CodeAppearance
 TextArea {
     height: 70; width: 160
 }

 TextArea {
     height: 70; width: 160
     placeholderText: "Enter Text Here"
 }

 TextArea {
     height: 70; width: 160
     text: "TextArea"
 }

 TextArea {
     height: 70; width: 160
     text: "TextArea"
     focus: true
 }

 TextArea {
     height: 70; width: 160
     text: "Text Area Text Area Text Area Text Area Text Area Text Area."
 }

Appearance while draging. See the Touch Interaction section.

 TextArea {
     height: 70; width: 160
     text: "TextArea"
     readOnly: true
 }

 TextArea {
     height: 70; width: 160
     text: "TextArea"
     enabled: false
 }

 TextArea {
     height: 70; width: 160
     text: "TextArea"
     errorHighlight: true
 }

TextArea Selection in Symbian

The examples below illustrate various TextArea selection features in Symbian.

Selected TextAdjust Selection

Place CursorPaste Menu

Implicit Size Behaviour

The text area resizes implicitly to accommodate more text. The maximum sizes are set with the platformMaxImplicitHeight and platformMaxImplicitWidth properties.

DescriptionMinimum Size
The minimum implicit size for a TextArea is 20 * " " on the current font.

If there is a placeholderText defined, its length is the text's minimum implicit size.

DescriptionGrowth pattern
With the default values a TextArea grows indefinitely to the right.
 TextArea {
     text: "TextArea TextArea TextArea TextArea"
 }

The platformMaxImplicitWidth setting defines a TextArea's wrapping point. When that width is reached the TextArea grows indefinitely downwards.
 TextArea {
     platformMaxImplicitWidth: 200
     text: "TextArea TextArea TextArea TextArea TextArea TextArea TextArea"
 }

The platformMaxImplicitHeight and platformMaxImplicitWidth settings restrict a TextArea to grow only to those values.
 TextArea {
     platformMaxImplicitHeight: 70
     platformMaxImplicitWidth: 200
     text: "TextArea TextArea TextArea TextArea TextArea TextArea TextArea"
 }

See also Entering Text with Split-view Input.

Property Documentation

cursorPosition : int

The position of the cursor in a TextArea.

See also TextEdit::cursorPosition.


enabled : bool

If the value is true, the user can interact with the TextArea; otherwise not.

The default value is true.

See also readOnly.


errorHighlight : bool

If the value is true, the TextArea's graphics show that it contains invalid input; otherwise not.


font : font

The text's font information in the TextArea.

See also TextEdit.


horizontalAlignment : int

verticalAlignment : int

Sets the horizontal and vertical alignment of the text within the TextArea item's width and height. By default, the text is top-left aligned.

For details of the options, see: TextEdit::horizontalAlignment


inputMethodHints : int

Settings that indicate what kind of input can be accepted by the TextArea. The value is from Qt::InputMethodHints.

See also Qt::InputMethodHints.


placeholderText : string

The placeholder text that is shown in the TextArea to hint at the expected input. The placeholder text is shown in the TextArea as long as it has no focus and the user has not entered any text to the TextArea. The default value of placeholderText is an empty string.


platformInverted : bool

Symbian:

If platformInverted is true, the component is visualized with the inverted style. For more information, see Using Inverted Style with Symbian Components. By default platformInverted is false.

This property group was introduced in Qt Quick Components 1.1.


platformMaxImplicitHeight : double

Defines the maximum height that the TextArea can grow to. If the height is explicitly set, this property has no effect.

The default value for this property is -1 meaning that the height is allowed to grow infinitely.

See also platformMaxImplicitWidth.


platformMaxImplicitWidth : double

Defines the maximum width that the TextArea can grow to. If the width is explicitly set, this property has no effect.

The default value for this property is -1 meaning that the width is allowed to grow infinitely.

See also platformMaxImplicitHeight.


readOnly : bool

If the value is true, the user can interact (select, copy, and scroll) with but not edit the TextArea's text. If the value is false, the user can also edit the text.

See also TextEdit::readOnly and enabled.


selectedText : string

The currently selected text in the text field.

See also TextEdit::selectedText.


selectionEnd : int

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

See also selectionStart, selectedText, cursorPosition, and TextEdit::selectionEnd.


selectionStart : int

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

See also selectionEnd, selectedText, cursorPosition, and TextEdit::selectionStart.


text : string

The text that has been entered into the text field.


textFormat : int

Defines whether the text is displayed as rich text or plain text. By default the format of the text is automatically determined.

See TextEdit::textFormat for the enumeration details.


wrapMode : int

Defines whether the text in the TextArea is wrapped or not.

See TextEdit::wrapMode for details of the different wrapping modes.


Method Documentation

TextArea::closeSoftwareInputPanel ()

Closes the virtual keyboard shown on the screen. On Symbian-based devices the user can open the virtual keyboard by tapping the TextArea.

Note: Currently closeSoftwareInputPanel does not work on Symbian. For more information, see QTBUG-20033.

See also openSoftwareInputPanel and TextEdit::closeSoftwareInputPanel().


TextArea::copy ()

Copies the currently selected text to the system clipboard.

See also paste, cut, and TextEdit::copy().


TextArea::cut ()

Moves the currently selected text to the system clipboard.

See also TextEdit::cut().


TextArea::openSoftwareInputPanel ()

Opens the virtual keyboard for typing. On Symbian-based devices the user can open the virtual keyboard by tapping the TextArea.

See also closeSoftwareInputPanel and TextEdit::openSoftwareInputPanel().


TextArea::paste ()

Replaces the currently selected text by the contents of the system clipboard.

See also copy, cut, and TextEdit::paste().


TextArea::positionAt ( x, y )

Returns the character position at x pixels from the left edge of the text field and y pixels from the top edge of the text field.

See also TextEdit::positionAt().


TextArea::positionToRectangle ( pos )

Returns the rectangle that the cursor would occupy if it was placed at pos character position.

This is similar to setting the cursorPosition and then querying the cursor rectangle, but the cursorPosition is not changed.

See also cursorPosition and TextEdit::positionToRectangle().


TextArea::select ( start, end )

Selects the text from start to end.

See also selectionStart, selectionEnd, and TextEdit::select().


TextArea::selectAll ()

Selects all the text in the text field.

See also TextEdit::selectAll().


TextArea::selectWord ()

Selects the word closest to the current cursor position.

See also TextEdit::selectWord().