TextInput QML Type

Displays an editable line of text. 更多...

import 语句: import QtQuick
继承:

Item

特性

信号

方法

详细描述

The TextInput type displays a single line of editable plain text.

TextInput is used to accept a line of text input. Input constraints can be placed on a TextInput item (for example, through a validator or inputMask ), and setting echoMode to an appropriate value enables TextInput to be used for a password input field.

On macOS, the Up/Down key bindings for Home/End are explicitly disabled. If you want such bindings (on any platform), you will need to construct them in QML.

另请参阅 TextEdit and Text .

特性文档编制

horizontalAlignment : enumeration

verticalAlignment : enumeration

Sets the horizontal alignment of the text within the TextInput 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.

TextInput 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 TextInput , use the read-only property effectiveHorizontalAlignment .

bottomPadding : real

leftPadding : real

padding : real

rightPadding : real

topPadding : real

These properties hold the padding around the content. This space is reserved in addition to the contentWidth and contentHeight .

The individual padding properties assume the value of the padding property unless they are set explicitly. For example, if padding 被设为 4 and leftPadding to 8 , 8 will be used as the left padding.

注意: If an explicit width or height is given to a TextInput , care must be taken to ensure it is large enough to accommodate the relevant padding values. For example: if topPadding and bottomPadding are set to 10 , but the height of the TextInput is only set to 20 , the text will not have enough vertical space in which to be rendered, and will appear clipped.

acceptableInput : bool [read-only]

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

是否 TextInput should gain active focus on a mouse press. By default this is set to true.

autoScroll : bool

是否 TextInput should scroll when the text is longer than the width. By default this is set to true.

另请参阅 ensureVisible ().

canPaste : bool [read-only]

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

canRedo : bool [read-only]

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

canUndo : bool [read-only]

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

color : color

文本颜色。

contentHeight : real [read-only]

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 [read-only]

Returns the width of the text, including the width past the width which is covered due to insufficient wrapping if wrapMode 有设置。

cursorDelegate : 组件

The delegate for the cursor in the TextInput .

If you set a cursorDelegate for a TextInput , 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 TextInput when a cursor is needed, and the x property of the 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 TextInput 。光标位于字符之间。

注意: The characters in this case refer to the string of QChar objects, therefore 16-bit Unicode characters, and the position is considered an index into this string. This does not necessarily correspond to individual graphemes in the writing system, as a single grapheme may be represented by multiple Unicode characters, such as in the case of surrogate pairs, linguistic ligatures or diacritics.

displayText is different if echoMode 被设为 TextInput.Password : then each passwordCharacter is a "narrow" character (the cursorPosition always moves by 1), even if the text in the TextInput is not.

cursorRectangle : rectangle [read-only]

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 TextInput shows a cursor.

This property is set and unset when the TextInput 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 and lost on focus changes.

TextInput {
    text: "Text"
    cursorVisible: false
}
					

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

displayText : string [read-only]

This is the text displayed in the TextInput .

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

注意: 不像 TextInput::text property, this contains partial text input from an input method.

另请参阅 preeditText .

echoMode : enumeration

Specifies how the text should be displayed in the TextInput .

常量 描述
TextInput.Normal Displays the text as it is. (Default)
TextInput.Password Displays platform-dependent password mask characters instead of the actual characters.
TextInput.NoEcho Displays nothing.
TextInput.PasswordEchoOnEdit Displays characters as they are entered while editing, otherwise identical to TextInput.Password .

effectiveHorizontalAlignment : enumeration [read-only]

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 TextInput , use the read-only property effectiveHorizontalAlignment .

font.bold : bool

Sets whether the font weight is bold.

font.capitalization : enumeration

Sets the capitalization for the text.

常量 描述
Font.MixedCase the normal case: no capitalization change is applied
Font.AllUppercase alters the text to be rendered in all uppercase type
Font.AllLowercase alters the text to be rendered in all lowercase type
Font.SmallCaps alters the text to be rendered in small-caps type
Font.Capitalize alters the text to be rendered with the first character of each word as an uppercase character
TextInput { text: "Hello"; font.capitalization: Font.AllLowercase }
								

font.family : string

Sets the family name of the font.

The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. If the family isn't available a family will be set using the font matching algorithm.

font.features : 对象 [since 6.6]

Applies integer values to specific OpenType features when shaping the text based on the contents in features . This provides advanced access to the font shaping process, and can be used to support font features that are otherwise not covered in the API.

The font features are represented by a map from four-letter tags to integer values. This integer value passed along with the tag in most cases represents a boolean value: A zero value means the feature is disabled, and a non-zero value means it is enabled. For certain font features, however, it may have other interpretations. For example, when applied to the salt feature, the value is an index that specifies the stylistic alternative to use.

例如, frac font feature will convert diagonal fractions separated with a slash (such as 1/2 ) with a different representation. Typically this will involve baking the full fraction into a single character width (such as ½ ).

If a font supports the frac feature, then it can be enabled in the shaper as in the following code:

Text {
    text: "One divided by two is 1/2"
    font.family: "MyFractionFont"
    font.features: { "frac": 1 }
}
					

Multiple features can be assigned values in the same mapping. For instance, if you would like to also disable kerning for the font, you can explicitly disable this as follows:

Text {
    text: "One divided by two is 1/2"
    font.family: "MyFractionFont"
    font.features: { "frac": 1, "kern": 0 }
}
					

You can also collect the font properties in an object:

Text {
    text: "One divided by two is 1/2"
    font: {
        family: "MyFractionFont"
        features: { "frac": 1, "kern": 0 }
    }
}
					

注意: By default, Qt will enable and disable certain font features based on other font properties. In particular, the kern feature will be enabled/disabled depending on the font.kerning 特性为 QFont . In addition, all ligature features ( liga , clig , dlig , hlig ) will be disabled if a font.letterSpacing is set, but only for writing systems where the use of ligature is cosmetic. For writing systems where ligatures are required, the features will remain in their default state. The values set using font.features will override the default behavior. If, for instance, "kern" is set to 1, then kerning will always be enabled, regardless of whether the font.kerning property is set to false. Similarly, if it is set to 0 , it will always be disabled.

该特性在 Qt 6.6 引入。

另请参阅 QFont::setFeature ().

font.hintingPreference : enumeration

Sets the preferred hinting on the text. This is a hint to the underlying text rendering system to use a certain level of hinting, and has varying support across platforms. See the table in the documentation for QFont::HintingPreference 了解更多细节。

注意: This property only has an effect when used together with render type TextInput .NativeRendering.

常量 描述
Font.PreferDefaultHinting Use the default hinting level for the target platform.
Font.PreferNoHinting If possible, render text without hinting the outlines of the glyphs. The text layout will be typographically accurate, using the same metrics as are used e.g. when printing.
Font.PreferVerticalHinting If possible, render text with no horizontal hinting, but align glyphs to the pixel grid in the vertical direction. The text will appear crisper on displays where the density is too low to give an accurate rendering of the glyphs. But since the horizontal metrics of the glyphs are unhinted, the text's layout will be scalable to higher density devices (such as printers) without impacting details such as line breaks.
Font.PreferFullHinting If possible, render text with hinting in both horizontal and vertical directions. The text will be altered to optimize legibility on the target device, but since the metrics will depend on the target size of the text, the positions of glyphs, line breaks, and other typographical detail will not scale, meaning that a text layout may look different on devices with different pixel densities.
TextInput { text: "Hello"; renderType: TextInput.NativeRendering; font.hintingPreference: Font.PreferVerticalHinting }
								

font.italic : bool

Sets whether the font has an italic style.

font.kerning : bool

Enables or disables the kerning OpenType feature when shaping the text. Disabling this may improve performance when creating or changing the text, at the expense of some cosmetic features. The default value is true.

TextInput { text: "OATS FLAVOUR WAY"; font.kerning: false }
					

font.letterSpacing : real

Sets the letter spacing for the font.

Letter spacing changes the default spacing between individual letters in the font. A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing.

font.pixelSize : int

Sets the font size in pixels.

使用此函数使字体设备从属。使用 pointSize to set the size of the font in a device independent manner.

font.pointSize : real

Sets the font size in points. The point size must be greater than zero.

font.preferShaping : bool

Sometimes, a font will apply complex rules to a set of characters in order to display them correctly. In some writing systems, such as Brahmic scripts, this is required in order for the text to be legible, but in e.g. Latin script, it is merely a cosmetic feature. Setting the preferShaping property to false will disable all such features when they are not required, which will improve performance in most cases.

默认值为 true。

TextInput { text: "Some text"; font.preferShaping: false }
					

font.strikeout : bool

Sets whether the font has a strikeout style.

font.styleName : string

Sets the style name of the font.

The style name is case insensitive. If set, the font will be matched against style name instead of the font properties font.weight , font.bold and font.italic .

font.underline : bool

Sets whether the text is underlined.

font.variableAxes : 对象 [since 6.7]

Applies floating point values to variable axes in variable fonts.

Variable fonts provide a way to store multiple variations (with different weights, widths or styles) in the same font file. The variations are given as floating point values for a pre-defined set of parameters, called "variable axes". Specific instances are typically given names by the font designer, and, in Qt, these can be selected using setStyleName() just like traditional sub-families.

In some cases, it is also useful to provide arbitrary values for the different axes. For instance, if a font has a Regular and Bold sub-family, you may want a weight in-between these. You could then manually request this by supplying a custom value for the "wght" axis in the font.

Text {
    text: "Foobar"
    font.family: "MyVariableFont"
    font.variableAxes: { "wght": (Font.Normal + Font.Bold) / 2.0 }
}
					

If the "wght" axis is supported by the font and the given value is within its defined range, a font corresponding to the weight 550.0 will be provided.

There are a few standard axes than many fonts provide, such as "wght" (weight), "wdth" (width), "ital" (italic) and "opsz" (optical size). They each have indivdual ranges defined in the font itself. For instance, "wght" may span from 100 to 900 ( QFont::Thin to QFont::Black ) whereas "ital" can span from 0 to 1 (from not italic to fully italic).

A font may also choose to define custom axes; the only limitation is that the name has to meet the requirements for a QFont::Tag (sequence of four latin-1 characters.)

By default, no variable axes are set.

注意: In order to use variable axes on Windows, the application has to run with either the FreeType or DirectWrite font databases. See the documentation for QGuiApplication::QGuiApplication () for more information on how to select these technologies.

This property was introduced in Qt 6.7.

另请参阅 QFont::setVariableAxis ().

font.weight : int

The requested weight of the font. The weight requested must be an integer between 1 and 1000, or one of the predefined values:

常量 描述
Font.Thin 100
Font.ExtraLight 200
Font.Light 300
Font.Normal 400 (default)
Font.Medium 500
Font.DemiBold 600
Font.Bold 700
Font.ExtraBold 800
Font.Black 900
TextInput { text: "Hello"; font.weight: Font.DemiBold }
								

font.wordSpacing : real

Sets the word spacing for the font.

单词间距改变单个单词之间的默认间距。正值按相应像素数量递增单词间距,而负值相应递减单词间间距。

inputMask : string

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

另请参阅 acceptableInput and validator .

inputMethodComposing : bool [read-only]

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 TextInput 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.
Qt.ImhSensitiveData 活动输入法不应该把键入文本存储在任何持久性存储中 (像预测用户字典)。
Qt.ImhNoAutoUppercase 输入法不应该试着自动切换到大写当句子结束时。
Qt.ImhPreferNumbers 数字是首选的 (但不是必需的)。
Qt.ImhPreferUppercase 大写字母是首选的 (但不是必需的)。
Qt.ImhPreferLowercase 小写字母是首选的 (但不是必需的)。
Qt.ImhNoPredictiveText 键入时不使用预测文本 (即:查找字典)。
Qt.ImhDate 作为日期字段的文本编辑器函数。
Qt.ImhTime 作为时间字段的文本编辑器函数。

Flags that restrict input (exclusive flags) are:

常量 描述
Qt.ImhDigitsOnly 只允许数字。
Qt.ImhFormattedNumbersOnly 只允许输入数字。这包括小数点和负号。
Qt.ImhUppercaseOnly 只允许输入大写字母。
Qt.ImhLowercaseOnly 只允许输入小写字母。
Qt.ImhDialableCharactersOnly 只允许适于电话拨号的字符。
Qt.ImhEmailCharactersOnly 只允许适于 Email 地址的字符。
Qt.ImhUrlCharactersOnly 只允许适于 URL 的字符。

掩码:

常量 描述
Qt.ImhExclusiveInputMask 此掩码产生非 0 若使用任何排斥标志。

length : int [read-only]

Returns the total number of characters in the TextInput 项。

TextInput has an inputMask the length will include mask characters and may differ from 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 TextInput 's internal string data.

maximumLength : int

The maximum permitted length of the text in the TextInput .

若文本太长,则在限制处截取它。

默认情况下,此特性包含 32767 值。

mouseSelectionMode : enumeration

Specifies how text should be selected using a mouse.

常量 描述
TextInput.SelectCharacters (default) The selection is updated with individual characters.
TextInput.SelectWords The selection is updated with whole words.

This property only applies when selectByMouse 为 true。

overwriteMode : bool

Whether text entered by the user will overwrite existing text.

As with many text editors, the text editor widget can be configured to insert or overwrite existing text with new text entered by the user.

若此特性为 true , existing text is overwritten, character-for-character by new text; otherwise, text is inserted at the cursor position, displacing existing text.

默认情况下,此特性为 false (新文本不覆写现有文本)。

passwordCharacter : string

This is the character displayed when echoMode is set to Password or PasswordEchoOnEdit. By default it is the password character used by the platform theme.

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.

passwordMaskDelay : int

Sets the delay before visible character is masked with password character, in milliseconds.

The reset method will be called by assigning undefined.

persistentSelection : bool

是否 TextInput should keep its selection when it loses active focus to another item in the scene. By default this is set to false;

preeditText : string [read-only]

This property contains partial text input from an input method.

To turn off partial text that results from predictions, set the Qt.ImhNoPredictiveText flag in inputMethodHints .

另请参阅 displayText and inputMethodHints .

readOnly : bool

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

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.

支持的渲染类型是:

常量 描述
TextInput.QtRendering Text is rendered using a scalable distance field for each glyph.
TextInput.NativeRendering Text is rendered using a platform-specific technique.
TextInput.CurveRendering Text is rendered using a curve rasterizer running directly on the graphics hardware. (Introduced in Qt 6.7.0.)

选择 TextInput.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.

Both TextInput.QtRendering and TextInput.CurveRendering are hardware-accelerated techniques. QtRendering is the faster of the two, but uses more memory and will exhibit rendering artifacts at large sizes. CurveRendering should be considered as an alternative in cases where QtRendering does not give good visual results or where reducing graphics memory consumption is a priority.

The default rendering type is determined by QQuickWindow::textRenderType ().

selectByMouse : bool

默认为 true .

If true, the user can use the mouse to select text in the usual way.

注意: In versions prior to 6.4, the default was false ; but if you enabled this property, you could also select text on a touchscreen by dragging your finger across it. This interfered with flicking when TextInput was used inside a Flickable. For consistency with TextField , selectByMouse now really means what it says: if true , you can select text by dragging only with a mouse. If this change does not suit your application, you can set selectByMouse to false , or import an older API version (for example import QtQuick 6.3 ) to revert to the previous behavior. The option to revert behavior by changing the import version will be removed in a later version of Qt.

selectedText : string [read-only]

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.

myTextInput.text.toString().substring(myTextInput.selectionStart,
    myTextInput.selectionEnd);
					

selectedTextColor : color

The highlighted text color, used in selections.

selectionColor : color

The text highlight color, used behind selections.

selectionEnd : int [read-only]

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 .

selectionStart : int [read-only]

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 .

text : string

The text in the TextInput .

Note that some keyboards use a predictive function. In this case, the text being composed by the input method is not part of this property. The part of the text related to the predictions is underlined and stored in the preeditText property. To get whole text displayed in the TextInput 使用 displayText 特性。

另请参阅 clear (), displayText ,和 preeditText .

validator : Validator

Allows you to set a validator on the TextInput . When a validator is set the TextInput 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 RegularExpressionValidator . An example of using validators is shown below, which allows input of integers between 11 and 31 into the text input:

import QtQuick 2.0
TextInput{
    validator: IntValidator{bottom: 11; top: 31;}
    focus: true
}
					

另请参阅 acceptableInput and inputMask .

wrapMode : enumeration

Set this property to wrap the text to the TextInput item's width. The text will only wrap if an explicit width has been set.

常量 描述
TextInput.NoWrap (default) no wrapping will be performed. If the text contains insufficient newlines, then contentWidth will exceed a set width.
TextInput.WordWrap wrapping is done on word boundaries only. If a word is too long, contentWidth will exceed a set width.
TextInput.WrapAnywhere wrapping is done at any point on a line, even if it occurs in the middle of a word.
TextInput.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.

默认为 TextInput .NoWrap. If you set a width, consider using TextInput .Wrap.

信号文档编制

accepted ()

此信号发射,当按下 Return/Enter 键。注意,若存在 validator or inputMask set on the text input, the signal will only be emitted if the input is in an acceptable state.

注意: 相应处理程序是 onAccepted .

editingFinished ()

This signal is emitted when the Return or Enter key is pressed or the text input loses focus. Note that if there is a validator or inputMask set on the text input and enter/return is pressed, this signal will only be emitted if the input follows the inputMask and the validator returns an acceptable state.

注意: 相应处理程序是 onEditingFinished .

textEdited ()

This signal is emitted whenever the text is edited. Unlike textChanged() , this signal is not emitted when the text is changed programmatically, for example, by changing the value of the text property or by calling clear() .

注意: 相应处理程序是 onTextEdited .

方法文档编制

clear ()

Clears the contents of the text input and resets partial text input from an input method.

Use this method instead of setting the text property to an empty string.

另请参阅 QInputMethod::reset ().

copy ()

Copies the currently selected text to the system clipboard.

注意: If the echo mode is set to a mode other than Normal then copy will not work. This is to prevent using copy as a method of bypassing password features of the line control.

cut ()

Moves the currently selected text to the system clipboard.

注意: If the echo mode is set to a mode other than Normal then cut will not work. This is to prevent using cut as a method of bypassing password features of the line control.

deselect ()

Removes active text selection.

ensureVisible ( int position )

Scrolls the contents of the text input so that the specified character position is visible inside the boundaries of the text input.

另请参阅 autoScroll .

string getText ( int start , int end )

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

TextInput has an inputMask the length will include mask characters.

insert ( int position , string text )

插入 text TextInput at position .

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.

moveCursorSelection ( int position , SelectionMode mode )

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

常量 描述
TextInput.SelectCharacters Sets either the selectionStart or selectionEnd (whichever was at the previous cursor position) to the specified position.
TextInput.SelectWords 设置 selectionStart and selectionEnd to include all words between the specified position and the previous cursor position. Words partially in the range are included.

For example, take this sequence of calls:

cursorPosition = 5
moveCursorSelection(9, TextInput.SelectCharacters)
moveCursorSelection(7, TextInput.SelectCharacters)
					

This moves the cursor to position 5, extend the selection end from 5 to 9 and then retract the selection end from 9 to 7, leaving the text from position 5 to 7 selected (the 6th and 7th characters).

The same sequence with TextInput .SelectWords will extend the selection start to a word boundary before or on position 5 and extend the selection end to a word boundary on or past position 9.

paste ()

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

int positionAt ( real x , real y , CursorPosition position )

This function returns the character position at x and y pixels from the top left of the textInput. 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.

This means that for all x values before the first character this function returns 0, and for all x values after the last character this function returns text.length. If the y value is above the text the position will be that of the nearest character on the first line and if it is below the text the position of the nearest character on the last line will be returned.

光标 position parameter specifies how the cursor position should be resolved:

常量 描述
TextInput.CursorBetweenCharacters Returns the position between characters that is nearest x. This is the default value.
TextInput.CursorOnCharacter Returns the position before the character that is nearest x.

rect positionToRectangle ( int pos )

This function takes a character position pos and returns the rectangle that the cursor would occupy, if it was placed at that character position.

This is similar to setting the cursorPosition , and then querying the cursor rectangle, but the cursorPosition 不改变。

redo ()

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

remove ( int start , int end )

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

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 .

selectAll ()

Causes all text to be selected.

selectWord ()

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

undo ()

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