Home · All Classes · All Functions · Overviews

QML TextEdit Element Reference

The TextEdit item allows you to add editable formatted text to a scene. More...

Properties

Detailed Description

It can display both plain and rich text. For example:

 TextEdit {
     id: edit
     text: "<b>Hello</b> <i>World!</i>"
     focus: true
     font.family: "Helvetica"
     font.pointSize: 20
     color: "blue"
     width: 240
 }

See also Text.


Property Documentation

color : color

The text color.

 // green text using hexadecimal notation
 TextEdit { color: "#00FF00"; ...  }

 // steelblue text using SVG color name
 TextEdit { color: "steelblue"; ...  }

cursorDelegate : Component

The delegate for the cursor in the TextEdit.

If you set a cursorDelegate for a TextEdit, 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 a QDeclarativeItem or QDeclarativeItem derived item.


cursorPosition : int

The position of the cursor in the TextEdit.


cursorVisible : bool

If true the text edit shows a cursor.

This property is set and unset when the text edit gets focus, but it can also be set directly (useful, for example, if a KeyProxy might forward keys to it).


focusOnPress : bool

Whether the TextEdit 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 TextEdit's font attributes.


horizontalAlignment : enumeration
verticalAlignment : enumeration

Sets the horizontal and vertical alignment of the text within the TextEdit items width and height. By default, the text is top-left aligned.

The valid values for horizontalAlignment are AlignLeft, AlignRight and AlignHCenter. The valid values for verticalAlignment are AlignTop, AlignBottom and AlignVCenter.


persistentSelection : bool

Whether the TextEdit should keep the selection visible when it loses focus to another item in the scene. By default this is set to true;


readOnly : bool

Whether the user an interact with the TextEdit item. If this property is set to true the text cannot be edited by user interaction.

By default this property is false.


selectedText : string

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 TextEdit
 myTextEdit.text.toString().substring(myTextEdit.selectionStart,
         myTextEdit.selectionEnd);

selectedTextColor : color

The selected 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.


text : string

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().


textFormat : enumeration

The way the text property should be displayed.

Supported text formats are AutoText, PlainText and RichText.

The default is AutoText. 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().

 Column {
     TextEdit {
         font.pointSize: 24
         text: "<b>Hello</b> <i>World!</i>"
     }
     TextEdit {
         font.pointSize: 24
         textFormat: "RichText"
         text: "<b>Hello</b> <i>World!</i>"
     }
     TextEdit {
         font.pointSize: 24
         textFormat: "PlainText"
         text: "<b>Hello</b> <i>World!</i>"
     }
 }


wrap : bool

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

Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default.



Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0