API Documentation
Documentation for developing SailfishOS applicationsTextArea QML Type
Displays multiple lines of editable plain text More...
Import Statement: | import Sailfish.Silica 1.0 |
Properties
- autoScrollEnabled : bool
- background : Component
- backgroundStyle : enumeration
- color : color
- cursorPosition : int
- description : string
- font.bold : bool
- font.capitalization : enumeration
- font.family : string
- font.italic : bool
- font.letterSpacing : real
- font.pixelSize : int
- font.pointSize : real
- font.strikeout : bool
- font.underline : bool
- font.weight : enumeration
- font.wordSpacing : real
- horizontalAlignment : enumeration
- inputMethodHints : Qt::InputMethodHints
- label : string
- labelVisible : bool
- leftItem : Item
- placeholderColor : string
- placeholderText : string
- readOnly : bool
- rightItem : Item
- selectedText : string
- selectionEnd : int
- selectionMode : enumeration
- selectionStart : int
- softwareInputPanelEnabled : bool
- text : string
- textLeftMargin : real
- textMargin : real
- textRightMargin : real
- textVerticalCenterOffset : real
- verticalAlignment : enumeration
- wrapMode : enumeration
Signals
- onClicked(variant mouse)
- onPressAndHold(variant mouse)
Methods
- copy()
- cut()
- deselect()
- forceActiveFocus()
- paste()
- int positionAt(x, y)
- rect positionToRectangle(position)
- select(start, end)
- selectAll()
- selectWord()
Detailed Description
The TextArea type provides a display for multiple lines of editable plain text.
Here is a simple text area:
import QtQuick 2.2 import Sailfish.Silica 1.0 TextArea { focus: true 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 consequat." }
TextArea height normally grows when user types more text with parent flickable used to scroll if the text doesn't fit on the device display at once.
The displayed text can be formatted through the font and color properties, though you should not need to touch those to follow the platform style. Text alignment is controlled through the horizontalAlignment and verticalAlignment properties, but normally you should let text follow its natural alignment. Text wrapping is controlled through the wrapMode property.
The label text is displayed below the input area when text is not empty, providing context for the text area. The convention typically used is:
TextArea { label: "Username" }
A text area can initially display some text that will automatically disappear once text is entered into the text area. This placeholder text is set through the placeholderText property:
import QtQuick 2.2 import Sailfish.Silica 1.0 TextArea { label: "Username" placeholderText: "Username" }
By default placeholderText follows the value of label text so just defining the label is enough in most cases.
See also TextField.
Property Documentation
Holds whether the text area will automatically scroll the Flickable that contains it to ensure visibility, when the text area gains active focus and when input is provided.
The default is true.
Style to use for the editor background.
Possible values
- TextEditor.UnderlineBackground - The text editor is rendered with an underline.
- TextEditor.FilledBackground - The text editor is rendered with a filled background.
- TextEditor.NoBackground - No background is rendered for the editor.
The default value is underlined background.
The character position of the cursor within the text.
The value ranges from 0 to the number of characters in text.
A longer text to display below the label, e.g. hint text or error message that provides some additional detail on what kind of input is expected.
The default value is an empty string.
See also text, label, and placeholderText.
Holds the capitalization formatting that is applied to the displayed text. This is one of:
- Font.MixedCase - no capitalization is applied (the default value)
- Font.AllUppercase - all text is rendered in uppercase
- Font.AllLowercase - all text is rendered in lowercase
- Font.SmallCaps - text is rendered in small caps
- Font.Capitalize - the first letter of each word is rendered with a capital letter
Controls the spacing (in pixels) between letters in the displayed text.
Specifying a positive value increases the default spacing between letters, and specifying a negative value decreases this spacing.
True if the displayed text is rendered with a strikeout style, otherwise false.
Holds the weight value for rendering the displayed text.
This is one of the following (listed from lightest to heaviest):
- Font.Light
- Font.Normal (the default value)
- Font.DemiBold
- Font.Bold
- Font.Black
Controls the spacing (in pixels) between words in the displayed text.
Specifying a positive value increases the default spacing between words, and specifying a negative value decreases this spacing.
The horizontal and vertical alignment of the text within the text area'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.
Valid values for horizontalAlignment are:
- TextEdit.AlignLeft (default)
- TextEdit.AlignRight
- TextEdit.AlignHCenter
- TextEdit.AlignJustify
Valid values for verticalAlignment are:
- TextEdit.AlignTop (default)
- TextEdit.AlignBottom
- TextEdit.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 TextArea, use the property LayoutMirroring::enabled.
Holds the hints to the input panel about the nature of the input this field expects. The input panel will display an input method suitable for the hints provided. The hints may be OR'ed together:
TextArea { inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoPredictiveText }
The supported input method hints are:
- Qt.ImhDialableCharactersOnly - Phone numbers
- Qt.ImhDigitsOnly - Integer numbers
- Qt.ImhEmailCharactersOnly - Email field
- Qt.ImhFormattedNumbersOnly - Decimal numbers
- Qt.ImhNoPredictiveText - Disable prediction
- Qt.ImhUrlCharactersOnly - Web address
- Qt.ImhNoAutoUppercase - Disable switch to uppercase at beginning of sentences
See also softwareInputPanelEnabled.
Text to display below the text entry area when text is not empty. This is useful for providing a description of the information to be entered in the text area. It is typically used in conjunction with placeholderText.
The default value is an empty string.
See also text, placeholderText, labelVisible, and description.
Use leftItem to inject an item to the left side of the displayed text. The most common use case is to add an icon that helps user identify the field
Note the left item is vertically centered to area that equals one-line text area, where as the right item is vertically centered to the first line of the visible text.
import QtQuick 2.2 import Sailfish.Silica 1.0 TextArea { label: "Note" leftItem: Icon { source: "image://theme/icon-m-note" } }
The color of the placeholderText.
By default, the color is Theme.secondaryHighlightColor when the text area has active focus, and Theme.secondaryColor otherwise.
See also placeholderText.
The text to be displayed when text is empty. This is useful for providing an indication of the information to be entered in the text area. It is typically used in conjunction with label.
By default the placeholder text value follows label text value.
See also text, placeholderColor, label, and description.
Holds whether the text area is in read-only mode.
If set to true, the user cannot edit the text.
Use rightItem to inject an item to the right side of the displayed text. The most common use case is to introduce an action like clear text as an icon button next to the text area.
Note the right item is vertically centered to the first line of the visible text, where as as the left item is vertically centered to an area that equeals one-line text area.
import QtQuick 2.2 import Sailfish.Silica 1.0 TextArea { id: clearableArea rightItem: IconButton { onClicked: clearableArea.text = "" width: icon.width height: icon.height icon.source: "image://theme/icon-m-input-clear" opacity: clearableArea.text.length > 0 ? 1.0 : 0.0 Behavior on opacity { FadeAnimation {} } } }
The position of the end of the selected text.
This is a readonly property. The user can modify the selection by double tapping the text and moving the handles. The selection can be set programmatically via the select(), selectAll() or selectWord() functions.
See also select() and selectedText.
Holds how text should be selected when dragging a selection handle. This is one of:
- TextEdit.SelectCharacters - The selection is updated character by character. (Default)
- TextEdit.SelectWords - The selection is updated word by word.
The position of the start of the selected text.
This is a readonly property. The user can modify the selection by double tapping the text and moving the handles. The selection can be set programmatically via the select(), selectAll() or selectWord() functions.
See also select() and selectedText.
Holds whether the on-screen key input panel is displayed when the text area gains active focus.
The default is true.
The margin to the left of the displayed text, within the bounds of the text area.
By default this follows textMargin, but also takes the width of leftItem if defined into account. The left item needs to have non-zero opacity to be counted in the default value.
The margin to the left and the right of the displayed text, within the bounds of the text area.
The margin to the right of the displayed text, within the bounds of the text area.
By default this follows textMargin, but also takes the width of rightItem if defined into account. The right item needs to have non-zero opacity to be counted in the default value.
The vertical offset from top of the text area to the center of the first line of the actual editor element. This property can be used for centering e.g. an icon with the editor element:
import QtQuick 2.2 import Sailfish.Silica 1.0 Page { TextArea { id: textArea } Image { anchors { left: textArea.right verticalCenter: textArea.top verticalCenterOffset: textArea.textVerticalCenterOffset } } }
The horizontal and vertical alignment of the text within the text area'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.
Valid values for horizontalAlignment are:
- TextEdit.AlignLeft (default)
- TextEdit.AlignRight
- TextEdit.AlignHCenter
- TextEdit.AlignJustify
Valid values for verticalAlignment are:
- TextEdit.AlignTop (default)
- TextEdit.AlignBottom
- TextEdit.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 TextArea, use the property LayoutMirroring::enabled.
Holds the mode used to wrap text to the width of the text area. The text will only wrap if an explicit width has been set.
- TextEdit.NoWrap - no wrapping will be performed. If the text contains insufficient newlines, then implicitWidth will exceed a set width.
- TextEdit.WordWrap - wrapping is done on word boundaries only. If a word is too long, implicitWidth will exceed a set width.
- 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.
The default is TextEdit.Wrap.
Signal Documentation
This signal handler is called when the text area is clicked. The mouse parameter provides information about the click.
This signal handler is called when there is a long press on the text area. The mouse parameter provides information about the press.
Method Documentation
Removes the text selection. The text remains unchanged.
See also select().
Forces active focus on the text area.
When an item has Item::activeFocus, it becomes the item that receives keyboard input.
If there is a selection then the selection will be replaced with the contents of the clipboard; otherwise inserts the contents of the clipboard into the text at the cursorPosition.
Returns a rectangle of the geometry where the cursor position would be if it was placed at the specified character position.
Selects the text from start to end.
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).
See also selectionStart, selectionEnd, and selectedText.
Selects all of the text.
See also select().
Selects the word nearest the cursorPosition.
See also select().