TextArea QML 类型

显示可编辑的多行格式化文本。 更多...

import 语句: import QtQuick.Controls 1.4
Since: Qt 5.1
继承: ScrollView

特性

信号

方法

详细描述

它可以显示纯文本和富文本。例如:

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() ,和 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 ,或使用 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 .

另请参阅 TextField and TextEdit .

特性文档编制

activeFocusOnPress : bool

是否 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.

默认值为 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 项。

[read-only] canPaste : bool

返回 true 若 TextArea is writable and the content of the clipboard is suitable for pasting into the TextArea .

[read-only] canRedo : bool

返回 true 若 TextArea is writable and there are undone operations that can be redone.

[read-only] canUndo : bool

返回 true 若 TextArea is writable and there are previous operations that can be undone.

[read-only] contentHeight : real

The height of the text content.

This property was introduced in QtQuick.Controls 1.3.

[read-only] contentWidth : real

The width of the text content.

This property was introduced in QtQuick.Controls 1.3.

cursorPosition : int

The position of the cursor in the TextArea .

[read-only] cursorRectangle : rect

The rectangle where the text cursor is rendered within the text area.

This property was introduced in QtQuick.Controls 1.3.

[read-only] effectiveHorizontalAlignment : enumeration

Gets the effective horizontal alignment of the text within the TextArea item's width.

To set/get the default horizontal alignment of TextArea , use the property horizontalAlignment .

font : font

The font of the TextArea .

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 是:

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 .

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

默认值为 Qt.ImhNone .

Flags that alter behavior are:

  • Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.
  • 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.

[read-only] length : int

Returns the total number of plain text characters in the TextArea 项。

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 特性。

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.

[read-only] lineCount : int

Returns the total number of lines in the TextArea 项。

This property contains the edit Menu for working with text selection. Set it to null if no menu is wanted.

This property was introduced in QtQuick.Controls 1.3.

另请参阅 Menu .

readOnly : bool

Whether the user can interact with the TextArea 项。

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.

默认情况下此特性为 false .

selectByKeyboard : bool

This property determines if the user can select the text with the keyboard.

若设为 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.

默认值为 true when the editor is editable, and false when read-only.

另请参阅 readOnly .

selectByMouse : bool

This property determines if the user can select the text with the mouse.

默认值为 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() ,或 selectWord() .

另请参阅 selectionStart , cursorPosition ,和 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() ,或 selectWord() .

另请参阅 selectionEnd , cursorPosition ,和 selectedText .

tabChangesFocus : bool

This property holds whether Tab changes focus, or is accepted as input.

默认为 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() .

textColor : color

文本颜色。

TextArea { textColor: "orange" }
																																	

textDocument : TextDocument

This property exposes the QQuickTextDocument of this TextArea .

另请参阅 TextEdit::textDocument .

textFormat : enumeration

The way the text property should be displayed.

默认为 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 property was introduced in QtQuick.Controls 1.1.

verticalAlignment : enumeration

Sets the alignment of the text within the TextArea item's height.

The valid values for verticalAlignment 是:

wrapMode : enumeration

Set this property to wrap the text to the TextArea item's width.

  • TextEdit .NoWrap - no wrapping will be performed.
  • TextEdit .WordWrap (default) - wrapping is done on word boundaries only.
  • TextEdit .WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word.
  • TextEdit .Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word.

信号文档编制

editingFinished ()

This signal is emitted when the text area loses focus.

相应处理程序是 onEditingFinished .

This signal was introduced in QtQuick.Controls 1.5.

linkActivated ( string = link)

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.

相应处理程序是 onLinkActivated .

linkHovered ( string = link)

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.

相应处理程序是 onLinkHovered .

This signal was introduced in QtQuick.Controls 1.1.

另请参阅 hoveredLink .


方法文档编制

void append ( string text )

追加 string as a new line to the end of the text area.

void copy ()

Copies the currently selected text to the system clipboard.

void cut ()

Moves the currently selected text to the system clipboard.

void deselect ()

Removes active text selection.

string getFormattedText ( int start , int end )

Returns the section of text that is between the start and end positions.

The returned text will be formatted according to the textFormat 特性。

string getText ( int start , int end )

Returns the section of text that is between the start and end positions.

The returned text does not include any rich text formatting.

void insert ( int position , string text )

插入 text TextArea at position.

bool isRightToLeft ( int start , int end )

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)

把光标移至 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 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.

void paste ()

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

int positionAt ( int x , int y )

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.

rectangle positionToRectangle ( position )

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.

void redo ()

重做上一操作,若重做 available .

string remove ( int start , int end )

Removes the section of text that is between the start and end positions from the TextArea .

void select ( int start , int end )

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).

另请参阅 selectionStart and selectionEnd .

void selectAll ()

Causes all text to be selected.

void selectWord ()

Causes the word closest to the current cursor position to be selected.

void undo ()

撤消上一操作,若撤消 available 。取消当前任何选定,并将选择起始更新成当前光标位置。