Displays a single line of editable plain text. 更多...
import 语句: | import QtQuick.Controls 1.4 |
Since: | Qt 5.1 |
继承: | FocusScope |
TextField is used to accept a line of text input. Input constraints can be placed on a TextField item (for example, through a validator or inputMask ). Setting echoMode to an appropriate value enables TextField to be used for a password input field.
TextField { placeholderText: qsTr("Enter name") }
You can create a custom appearance for a TextField by assigning a TextFieldStyle .
返回
true
if the text field contains acceptable text.
If a validator or input mask was set, this property will return
true
if the current text satisfies the validator or mask as a final string (not as an intermediate string).
默认值为
true
.
另请参阅 validator , inputMask ,和 accepted .
This property is set to
true
若
TextField
should gain active focus on a mouse press.
默认值为
true
.
返回
true
若
TextField
is writable and the content of the clipboard is suitable for pasting into the
TextField
.
返回
true
若
TextField
is writable and there are
undone
operations that can be redone.
返回
true
若
TextField
is writable and there are previous operations that can be undone.
This property holds the position of the cursor in the TextField .
The rectangle where the text cursor is rendered within the text field.
This QML property was introduced in QtQuick.Controls 1.3.
This property holds the text displayed in the TextField .
若 echoMode is set to TextInput::Normal, this holds the same value as the TextField::text property. Otherwise, this property holds the text visible to the user, while the text property holds the actual entered text.
Specifies how the text should be displayed in the TextField .
The possible modes are:
Gets the effective horizontal alignment of the text within the TextField item's width.
horizontalAlignment contains the default horizontal alignment.
另请参阅 horizontalAlignment .
font : font |
Sets the font of the TextField .
Sets the alignment of the text within the TextField 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 possible alignment values 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
TextField
, use the read-only property
effectiveHorizontalAlignment
.
This property holds whether the control is being hovered.
Sets an input mask on the TextField , restricting the allowable text inputs. See QLineEdit::inputMask for further details, as the exact same mask strings are used by TextField .
另请参阅 acceptableInput and validator .
This property holds whether the TextField has partial text input from an input method.
While it is composing an input method may rely on mouse or key events from the TextField 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 field 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:
TextInput.Password
.
Flags that restrict input (exclusive flags) are:
掩码:
Returns the total number of characters in the TextField 项。
若 TextField has an input mask, 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 of the text property as it doesn't require any copying or conversion of the TextField 's internal string data.
This property holds the maximum permitted length of the text in the TextField .
若文本太长,则在限制处截取它。
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.
This property contains the text that is shown in the text field when the text field is empty.
Sets whether user input can modify the contents of the TextField . Read- only is different from a disabled text field in that the text field will appear to be active and text can still be selected and copied.
If readOnly is set to
true
, then user input will not affect the text. Any bindings or attempts to set the text property will still work, however.
This property determines if the user can select the text with the mouse.
默认值为
true
.
This QML property was introduced in QtQuick.Controls 1.3.
Provides the text currently selected in the text input.
It is equivalent to the following snippet, but is faster and easier to use.
myTextField.text.toString().substring(myTextField.selectionStart, myTextField.selectionEnd);
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 .
style : Component |
The style Component for this control.
另请参阅 Qt Quick Controls Styles QML Types .
This property contains the text in the TextField .
This property holds the text color.
Allows you to set a validator on the TextField . When a validator is set, the TextField will only accept input which leaves the text property in an 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 ,和 RegExpValidator . An example of using validators is shown below, which allows input of integers between 11 and 31 into the text input:
import QtQuick 2.2 import QtQuick.Controls 1.2 TextField { validator: IntValidator {bottom: 11; top: 31;} focus: true }
另请参阅 acceptableInput , inputMask ,和 accepted .
Sets the alignment of the text within the TextField item's height.
The possible alignment values are:
此信号被发射,当 Return 或 Enter 键被按下。注意, 若存在 validator or inputMask set on the text field, the signal will only be emitted if the input is in an acceptable state.
相应处理程序是
onAccepted
.
This signal is emitted when the Return or Enter key is pressed or the text field loses focus. Note that if there is a validator or inputMask set on the text field 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
.
This QML signal was introduced in QtQuick.Controls 1.1.
Copies the currently selected text to the system clipboard.
Moves the currently selected text to the system clipboard.
Removes active text selection.
Removes the section of text that is between the start and end positions from the TextField .
插入 text 到 TextField at position .
返回
true
if the natural reading direction of the editor text found between positions
start
and
end
is right to left.
Replaces the currently selected text by the contents of the system clipboard.
Performs the last operation if redo is available .
Removes the section of text that is between the start and end positions.
This QML method was introduced in QtQuick.Controls 1.4.
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 select, 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.
Reverts the last operation if undo is available . undo() deselects any current selection and updates the selection start to the current cursor position.