Displays multiple lines of editable formatted text. More...
Import Statement: | import QtQuick.Controls 1.4 |
Since: | Qt 5.1 |
Inherits: |
It can display both plain and rich text. For example:
TextArea { width: 240 text: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna " + "aliqua. Ut enim ad minim veniam, quis nostrud exercitation " + "ullamco laboris nisi ut aliquip ex ea commodo cosnsequat. "; }
Clipboard support is provided by the cut(), copy(), and paste() functions, and the selection can be handled in a traditional "mouse" mechanism by setting selectByMouse, or handled completely from QML by manipulating selectionStart and selectionEnd, or using selectAll() or selectWord().
You can translate between cursor positions (characters from the start of the document) and pixel points using positionAt() and positionToRectangle().
You can create a custom appearance for a TextArea by assigning a TextAreaStyle.
See also TextField and TextEdit.
activeFocusOnPress : bool |
Whether the TextEdit should gain active focus on a mouse press. By default this is set to true.
backgroundVisible : bool |
This property determines if the background should be filled or not.
The default value is true
.
baseUrl : url |
This property specifies a base URL which is used to resolve relative URLs within the text.
The default value is the url of the QML file instantiating the TextArea item.
[read-only] canPaste : bool |
[read-only] canRedo : bool |
[read-only] canUndo : bool |
Returns true if the TextArea is writable and there are previous operations that can be undone.
[read-only] contentHeight : real |
The height of the text content.
This QML property was introduced in QtQuick.Controls 1.3.
[read-only] contentWidth : real |
The width of the text content.
This QML property was introduced in QtQuick.Controls 1.3.
[read-only] cursorRectangle : rect |
The rectangle where the text cursor is rendered within the text area.
This QML property was introduced in QtQuick.Controls 1.3.
[read-only] effectiveHorizontalAlignment : enumeration |
horizontalAlignment : enumeration |
Sets the alignment of the text within the TextArea item's width.
By default, the horizontal 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.
The valid values for horizontalAlignment
are:
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 TextArea, use the read-only property
effectiveHorizontalAlignment
.
[read-only] hoveredLink : string |
This property contains the link string when user hovers a link embedded in the text. The link must be in rich text or HTML format and the link string provides access to the particular link.
This QML property was introduced in QtQuick.Controls 1.1.
[read-only] inputMethodComposing : bool |
This property holds whether the TextArea has partial text input from an input method.
While it is composing an input method may rely on mouse or key events from the TextArea 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.
This QML property was introduced in QtQuick.Controls 1.3.
inputMethodHints : enumeration |
Provides hints to the input method about the expected content of the text edit, and how it should operate.
The value is a bit-wise combination of flags or Qt.ImhNone if no hints are set.
The default value is Qt.ImhNone
.
Flags that alter behavior are:
Flags that restrict input (exclusive flags) are:
Masks:
[read-only] length : int |
Returns the total number of plain text characters in the TextArea item.
As this number doesn't include any formatting markup, it may not be the same as 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 TextArea's internal string data.
menu : Component |
readOnly : bool |
Whether the user can interact with the TextArea item.
The difference from a disabled text field is that it will appear to be active, and text can be selected and copied.
If this property is set to true
, the text cannot be edited by user interaction.
By default this property is false
.
selectByKeyboard : bool |
This property determines if the user can select the text with the keyboard.
If set to true
, the user can use the keyboard to select the text even if the editor is read-only. If set to false
, the user cannot use the keyboard to select the text even if the editor is
editable.
The default value is true
when the editor is editable, and false
when read-only.
See also readOnly.
selectByMouse : bool |
This property determines if the user can select the text with the mouse.
The default value is true
.
[read-only] selectedText : string |
This read-only property provides the text currently selected in the text edit.
[read-only] 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().
See also selectionStart, cursorPosition, and selectedText.
[read-only] 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().
See also selectionEnd, cursorPosition, and selectedText.
tabChangesFocus : bool |
This property holds whether Tab changes focus, or is accepted as input.
Defaults to false
.
text : string |
The text to display. If the text format is AutoText the text edit will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText().
This property exposes the QQuickTextDocument of this TextArea.
See also TextEdit::textDocument.
textFormat : enumeration |
The way the text property should be displayed.
The default is TextEdit.PlainText. If the text format is TextEdit.AutoText the text edit will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText().
textMargin : real |
The margin, in pixels, around the text in the TextArea.
This QML property was introduced in QtQuick.Controls 1.1.
verticalAlignment : enumeration |
wrapMode : enumeration |
Set this property to wrap the text to the TextArea item's width.
This signal is emitted when the text area loses focus.
The corresponding handler is onEditingFinished
.
This QML signal was introduced in QtQuick.Controls 1.5.
This signal is emitted when the user clicks on a link embedded in the text. The link must be in rich text or HTML format and the link string provides access to the particular link.
The corresponding handler is onLinkActivated
.
This signal is emitted when the user hovers a link embedded in the text. The link must be in rich text or HTML format and the link string provides access to the particular link.
The corresponding handler is onLinkHovered
.
This QML signal was introduced in QtQuick.Controls 1.1.
See also hoveredLink.
void append(string text) |
Appends string as a new line to the end of the text area.
Returns the section of text that is between the start and end positions.
The returned text will be formatted according to the textFormat property.
Returns the section of text that is between the start and end positions.
The returned text does not include any rich text formatting.
Returns true if the natural reading direction of the editor text found between positions start and end is right to left.
void moveCursorSelection(int position, SelectionMode mode = TextEdit.SelectCharacters) |
Moves the cursor to position and updates the selection according to the optional mode parameter. (To only move the cursor, set the cursorPosition property.)
When this method is called it additionally sets either the selectionStart or the selectionEnd (whichever was at the previous cursor position) to the specified position. This allows you to easily extend and contract the selected text range.
The selection mode specifies whether the selection is updated on a per character or a per word basis. If not specified the selection mode will default to TextEdit.SelectCharacters.
For example, take this sequence of calls:
cursorPosition = 5 moveCursorSelection(9, TextEdit.SelectCharacters) moveCursorSelection(7, TextEdit.SelectCharacters)
This moves the cursor to the 5th position, extends the selection end from 5 to 9, and then retracts the selection end from 9 to 7, leaving the text from the 5th position to the 7th position selected (the 6th and 7th characters).
The same sequence with TextEdit.SelectWords will extend the selection start to a word boundary before or on the 5th position, and extend the selection end to a word boundary on or past the 9th position.
Returns the text position closest to pixel position (x, y).
Position 0 is before the first character, position 1 is after the first character but before the second, and so on until position text.length, which is after all characters.
Returns the rectangle at the given position in the text. The x, y, and height properties correspond to the cursor that would describe that position.
Redoes the last operation if redo is available.
Removes the section of text that is between the start and end positions from the TextArea.
Causes the text from start to end to be selected.
If either start or end is out of range, the selection is not changed.
After calling this, selectionStart will become the lesser and selectionEnd will become the greater (regardless of the order passed to this method).
See also selectionStart and selectionEnd.
Undoes the last operation if undo is available. Deselects any current selection, and updates the selection start to the current cursor position.