![]() |
Home · All Classes · All Functions · Overviews |
|
|
The TextInput item allows you to add an editable line of text to a scene.
TextInput can only display a single line of text, and can only display plain text. However it can provide addition input constraints on the text.
Input constraints include setting a QValidator, an input mask, or a maximum input length.
read-onlyacceptableInput : bool |
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).
color : color |
The text color.
cursorDelegate : Component |
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 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 QDeclarativeItem or QDeclarativeItem derived item.
cursorVisible : bool |
Set to true when the TextInput shows a cursor.
This property is set and unset when the TextInput gets 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 the focus).
It should not be set directly on the element, like in the below QML, as the specified value will be overridden an lost on focus changes.
TextInput { text: "Text" cursorVisible: false }
In the above snippet the cursor will still become visible when the TextInput gains focus.
Specifies how the text should be displayed in the TextInput. The default is Normal, which displays the text as it is. Other values are Password, which displays asterixes instead of characters, NoEcho, which displays nothing, and PasswordEchoOnEdit, which displays all but the current character as asterixes.
focusOnPress : bool |
Whether the TextInput should gain focus on a mouse press. By default this is set to true.
font.family : string |
font.bold : bool |
font.italic : bool |
font.underline : bool |
font.pointSize : real |
font.pixelSize : int |
Set the TextInput's font attributes.
Sets the horizontal alignment of the text within the TextInput item's width and height. By default, the text is left aligned.
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 AlignLeft, AlignRight and AlignHCenter.
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.
See also acceptableInput and validator.
read-onlyselectedText : string |
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 |
The cursor position after the last character in the current selection. Setting this and selectionStart allows you to specify a selection in the text edit.
Note that if selectionStart == selectionEnd then there is no current selection. If you attempt to set selectionEnd to a value outside of the current text, selectionEnd will not be changed.
See also selectionStart, cursorPosition, and selectedText.
selectionStart : int |
The cursor position before the first character in the current selection. Setting this and selectionEnd allows you to specify a selection in the text edit.
Note that if selectionStart == selectionEnd then there is no current selection. If you attempt to set selectionStart to a value outside of the current text, selectionStart will not be changed.
See also selectionEnd, cursorPosition, and selectedText.
smooth : bool |
Set this property if you want the text to be smoothly scaled or transformed. Smooth filtering gives better visual quality, but is slower. If the item is displayed at its natural size, this property has no visual or performance effect.
Note: Generally scaling artifacts are only visible if the item is stationary on the screen. A common pattern when animating an item is to disable smooth filtering at the beginning of the animation and reenable it at the conclusion.
validator : QValidator* |
Allows you to set a QValidator 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 QIntValidator, QDoubleValidator and QRegExpValidator. For details, refer to their C++ documentation and remember that all Q_PROPERTIES are accessible from Qml. A brief usage guide follows:
QIntValidator and QDoubleValidator both are controllable through two properties, top and bottom. The difference is that for QIntValidator the top and bottom properties should be integers, and for QDoubleValidator they should be doubles. QRegExpValidator has a single string property, regExp, which should be set to the regular expression to be used for validation. An example of using validators is shown below, which allows input of integers between 11 and 31 into the text input:
import Qt 4.6 TextInput{ validator: QIntValidator{bottom: 11; top: 31;} focus: true }
See also acceptableInput and inputMask.
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.7.0 |