显示可编辑的多行格式化文本。 更多...
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 .
是否 TextEdit should gain active focus on a mouse press. By default this is set to true.
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 项。
返回 true 若 TextArea is writable and the content of the clipboard is suitable for pasting into the TextArea .
返回 true 若 TextArea is writable and there are undone operations that can be redone.
返回 true 若 TextArea is writable and there are previous operations that can be undone.
The height of the text content.
This QML property was introduced in QtQuick.Controls 1.3.
The width of the text content.
This QML property was introduced in QtQuick.Controls 1.3.
The position of the cursor in the TextArea .
The rectangle where the text cursor is rendered within the text area.
This QML property was introduced in QtQuick.Controls 1.3.
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 .
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 QML property was introduced in QtQuick.Controls 1.1.
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.
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:
Flags that restrict input (exclusive flags) are:
掩码:
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.
Returns the total number of lines in the TextArea 项。
menu : Component |
This property contains the edit
Menu
for working with text selection. Set it to
null
if no menu is wanted.
This QML property was introduced in QtQuick.Controls 1.3.
另请参阅 Menu .
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
.
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 .
This property determines if the user can select the text with the mouse.
默认值为
true
.
This read-only property provides the text currently selected in the text edit.
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 .
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 .
This property holds whether Tab changes focus, or is accepted as input.
默认为
false
.
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() .
文本颜色。
TextArea { textColor: "orange" }
This property exposes the QQuickTextDocument of this TextArea .
另请参阅 TextEdit::textDocument .
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() .
The margin, in pixels, around the text in the TextArea .
This QML property was introduced in QtQuick.Controls 1.1.
Sets the alignment of the text within the TextArea item's height.
The valid values for
verticalAlignment
是:
Set this property to wrap the text to the TextArea item's width.
This signal is emitted when the text area loses focus.
相应处理程序是
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.
相应处理程序是
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.
相应处理程序是
onLinkHovered
.
This QML signal was introduced in QtQuick.Controls 1.1.
另请参阅 hoveredLink .
追加 string as a new line to the end of the text area.
Copies the currently selected text to the system clipboard.
Moves the currently selected text to the system clipboard.
Removes active text selection.
Returns the section of text that is between the start and end positions.
The returned text will be formatted according to the textFormat 特性。
Returns the section of text that is between the start and end positions.
The returned text does not include any rich text formatting.
插入 text 到 TextArea at position.
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.
Replaces the currently selected text by the contents of the system clipboard.
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.
重做上一操作,若重做 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).
另请参阅 selectionStart and selectionEnd .
Causes all text to be selected.
Causes the word closest to the current cursor position to be selected.
撤消上一操作,若撤消 available 。取消当前任何选定,并将选择起始更新成当前光标位置。