
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheTextEdit item displays multiple lines of editable formatted text.More...
| Since: | Qt 4.7 |
| Inherits: |
TheTextEdit item displays a block of editable, formatted text.
It can display both plain and rich text. For example:
TextEdit {width:240text:"<b>Hello</b> <i>World!</i>"font.family:"Helvetica"font.pointSize:20color:"blue"focus:true}
Settingfocus totrue enables theTextEdit item to receive keyboard focus.
Note that theTextEdit does not implement scrolling, following the cursor, or other behaviors specific to a look-and-feel. For example, to add flickable scrolling that follows the cursor:
Flickable {id:flickwidth:300;height:200;contentWidth:edit.paintedWidthcontentHeight:edit.paintedHeightclip:truefunctionensureVisible(r) {if (contentX>=r.x)contentX=r.x;elseif (contentX+width<=r.x+r.width)contentX=r.x+r.width-width;if (contentY>=r.y)contentY=r.y;elseif (contentY+height<=r.y+r.height)contentY=r.y+r.height-height; }TextEdit {id:editwidth:flick.widthheight:flick.heightfocus:truewrapMode:TextEdit.WraponCursorRectangleChanged:flick.ensureVisible(cursorRectangle) }}
A particular look-and-feel might use smooth scrolling (eg. using SmoothedFollow), might have a visible scrollbar, or a scrollbar that fades in to show location, etc.
Clipboard support is provided by thecut(),copy(), andpaste() functions, and the selection can be handled in a traditional "mouse" mechanism by settingselectByMouse, or handled completely from QML by manipulatingselectionStart andselectionEnd, or usingselectAll() orselectWord().
You can translate between cursor positions (characters from the start of the document) and pixel points usingpositionAt() andpositionToRectangle().
See alsoText,TextInput, andText Selection example.
Whether theTextEdit should gain active focus on a mouse press. By default this is set to true.
cursorDelegate :Component |
The delegate for the cursor in theTextEdit.
If you set a cursorDelegate for aTextEdit, 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 text edit when a cursor is needed, and the x and y properties 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 aQDeclarativeItem orQDeclarativeItem derived item.
The position of the cursor in theTextEdit.
The rectangle where the text cursor is rendered within the text edit. Read-only.
If true the text edit shows a cursor.
This property is set and unset when the text edit gets active focus, but it can also be set directly (useful, for example, if a KeyProxy might forward keys to it).
Sets the capitalization for the text.
TextEdit {text:"Hello";font.capitalization:Font.AllLowercase }
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.
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.
Sets the font size in pixels.
Using this function makes the font device dependent. UseTextEdit::font.pointSize to set the size of the font in a device independent manner.
Sets the font's weight.
The weight can be one of:
TextEdit {text:"Hello";font.weight:Font.DemiBold }
Sets the word spacing for the font.
Word spacing changes the default spacing between individual words. A positive value increases the word spacing by a corresponding amount of pixels, while a negative value decreases the inter-word spacing accordingly.
Sets the horizontal and vertical alignment of the text within theTextEdit 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.
Valid values forhorizontalAlignment are:
Valid values forverticalAlignment are:
When using the attached propertyLayoutMirroring::enabled to mirror application layouts, the horizontal alignment of text will also be mirrored. However, the propertyhorizontalAlignment will remain unchanged. To query the effective horizontal alignment ofTextEdit, use the propertyLayoutMirroring::enabled.
This property holds whether theTextEdit has partial text input from an input method.
While it is composing an input method may rely on mouse or key events from theTextEdit 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 1.1.
Returns the total number of lines in the textEdit item.
This QML property was introduced in QtQuick 1.1.
Specifies how text should be selected using a mouse.
This property only applies whenselectByMouse is true.
This QML property was introduced in QtQuick 1.1.
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.
Returns the width of the text, including the width past the width which is covered due to insufficient wrapping ifwrapMode is set.
Whether theTextEdit should keep the selection visible when it loses active focus to another item in the scene. By default this is set to true;
Whether the user an interact with theTextEdit item. If this property is set to true the text cannot be edited by user interaction.
By default this property is false.
Defaults to false.
If true, the user can use the mouse to select text in some platform-specific way. Note that for some platforms this may not be an appropriate interaction (eg. may conflict with how the text needs to behave inside a Flickable.
This read-only property provides the text currently selected in the text edit.
It is equivalent to the following snippet, but is faster and easier to use.
//myTextEdit is the id of the TextEditmyTextEdit.text.toString().substring(myTextEdit.selectionStart, myTextEdit.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(), orselectWord().
See alsoselectionStart,cursorPosition, andselectedText.
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(), orselectWord().
See alsoselectionEnd,cursorPosition, andselectedText.
This property holds whether the text is 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.
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().
Sets the horizontal and vertical alignment of the text within theTextEdit 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.
Valid values forhorizontalAlignment are:
Valid values forverticalAlignment are:
When using the attached propertyLayoutMirroring::enabled to mirror application layouts, the horizontal alignment of text will also be mirrored. However, the propertyhorizontalAlignment will remain unchanged. To query the effective horizontal alignment ofTextEdit, use the propertyLayoutMirroring::enabled.
Set this property to wrap the text to theTextEdit item's width. The text will only wrap if an explicit width has been set.
The default isTextEdit.NoWrap. If you set a width, consider usingTextEdit.Wrap.
This handler is called when the user clicks on a link embedded in the text. The link must be in rich text or HTML format and thelink string provides access to the particular link.
This QML signal was introduced in QtQuick 1.1.
Closes a software input panel like a virtual keyboard shown on the screen, useful for customizing when you want the input keyboard to be shown and hidden in your application.
By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clickingTextEdit. On other platforms the panels are automatically opened whenTextEdit element gains active focus. Input panels are always closed if no editor has active focus.
You can disable the automatic behavior by setting the propertyactiveFocusOnPress to false and use functionsopenSoftwareInputPanel() and closeSoftwareInputPanel() to implement the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
importQtQuick1.0TextEdit { id: textEdit text:"Hello world!" activeFocusOnPress:false MouseArea { anchors.fill: parent onClicked: {if (!textEdit.activeFocus) { textEdit.forceActiveFocus(); textEdit.openSoftwareInputPanel(); }else { textEdit.focus=false; } } onPressAndHold: textEdit.closeSoftwareInputPanel(); }}
Returns true if the natural reading direction of the editor text found between positionsstart andend is right to left.
Moves the cursor toposition and updates the selection according to the optionalmode parameter. (To only move the cursor, set thecursorPosition property.)
When this method is called it additionally sets either theselectionStart or theselectionEnd (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 toTextEdit.SelectCharacters.
For example, take this sequence of calls:
cursorPosition=5moveCursorSelection(9, TextEdit.SelectCharacters)moveCursorSelection(7, TextEdit.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 withTextEdit.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.
This QML method was introduced in QtQuick 1.1.
Opens software input panels like virtual keyboards for typing, useful for customizing when you want the input keyboard to be shown and hidden in your application.
By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clickingTextEdit. On other platforms the panels are automatically opened whenTextEdit element gains active focus. Input panels are always closed if no editor has active focus.
You can disable the automatic behavior by setting the propertyactiveFocusOnPress to false and use functions openSoftwareInputPanel() andcloseSoftwareInputPanel() to implement the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
importQtQuick1.0TextEdit { id: textEdit text:"Hello world!" activeFocusOnPress:false MouseArea { anchors.fill: parent onClicked: {if (!textEdit.activeFocus) { textEdit.forceActiveFocus(); textEdit.openSoftwareInputPanel(); }else { textEdit.focus=false; } } onPressAndHold: textEdit.closeSoftwareInputPanel(); }}
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 positiontext.length, which is after all characters.
Returns the rectangle at the givenposition in the text. The x, y, and height properties correspond to the cursor that would describe that position.
Causes the text fromstart toend 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 andselectionEnd will become the greater (regardless of the order passed to this method).
See alsoselectionStart andselectionEnd.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.