QTextEdit

继承者: QTextBrowser

概要

详细描述

PySide.QtGui.QTextEdit class provides a widget that is used to edit and display both plain and rich text.

介绍和概念

PySide.QtGui.QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags. It is optimized to handle large documents and to respond quickly to user input.

PySide.QtGui.QTextEdit works on paragraphs and characters. A paragraph is a formatted string which is word-wrapped to fit into the width of the widget. By default when reading plain text, one newline signifies a paragraph. A document consists of zero or more paragraphs. The words in the paragraph are aligned in accordance with the paragraph's alignment. Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color.

PySide.QtGui.QTextEdit can display images, lists and tables. If the text is too large to view within the text edit's viewport, scroll bars will appear. The text edit can load both plain text and HTML files (a subset of HTML 3.2 and 4).

若仅仅需要显示小段富文本使用 PySide.QtGui.QLabel .

The rich text support in Qt is designed to provide a fast, portable and efficient way to add reasonable online help facilities to applications, and to provide a basis for rich text editors. If you find the HTML support insufficient for your needs you may consider the use of QtWebKit , which provides a full-featured web browser widget.

The shape of the mouse cursor on a PySide.QtGui.QTextEdit is Qt.IBeamCursor 默认情况下。它可以被改变透过 PySide.QtGui.QAbstractScrollArea.viewport() ‘s cursor property.

使用 QTextEdit 作为显示 Widget

PySide.QtGui.QTextEdit can display a large HTML subset, including tables and images.

设置或替代文本使用 PySide.QtGui.QTextEdit.setHtml() which deletes any existing text and replaces it with the text passed in the PySide.QtGui.QTextEdit.setHtml() call. If you call PySide.QtGui.QTextEdit.setHtml() with legacy HTML, and then call PySide.QtGui.QTextEdit.toHtml() , the text that is returned may have different markup, but will render the same. The entire text can be deleted with PySide.QtGui.QTextEdit.clear() .

可以插入文字本身使用 PySide.QtGui.QTextCursor 类或使用方便函数 PySide.QtGui.QTextEdit.insertHtml() , PySide.QtGui.QTextEdit.insertPlainText() , PySide.QtGui.QTextEdit.append() or PySide.QtGui.QTextEdit.paste() . PySide.QtGui.QTextCursor 还能够把复杂对象 (像:表格或列表) 插入文档,且它能够处理创建选择并将改变应用到选中文本。

默认情况下,文本编辑在空白处自动换行以拟合在文本编辑 Widget 中。 PySide.QtGui.QTextEdit.setLineWrapMode() function is used to specify the kind of line wrap you want, or NoWrap 若不想要任何换行。调用 PySide.QtGui.QTextEdit.setLineWrapMode() to set a fixed pixel width FixedPixelWidth ,或字符列 (如:80 列) FixedColumnWidth 按指定像素或列数采用 PySide.QtGui.QTextEdit.setLineWrapColumnOrWidth() . If you use word wrap to the widget's width WidgetWidth ,可以指定是在空白处断开还是在任何地方断开采用 PySide.QtGui.QTextEdit.setWordWrapMode() .

PySide.QtGui.QTextEdit.find() function can be used to find and select a given string within the text.

If you want to limit the total number of paragraphs in a PySide.QtGui.QTextEdit , as for example it is often useful in a log viewer, then you can use PySide.QtGui.QTextDocument ‘s maximumBlockCount property for that.

只读键绑定

PySide.QtGui.QTextEdit is used read-only the key bindings are limited to navigation, and text may only be selected with the mouse:

Keypresses Action
Up 向上移动一行。
Down 向下移动一行。
Left 向左移动一字符。
Right 向右移动一字符。
PageUp 向上移动一 (视口) 页。
PageDown 向下移动一 (视口) 页。
首页 移动到文本的起始。
End 移动到文本的结尾。
Alt+Wheel 水平卷动页面 (Wheel 是鼠标滚轮)。
Ctrl+Wheel 缩放文本。
Ctrl+A 选择所有文本。

文本编辑可能能够提供一些元信息。例如, PySide.QtGui.QTextEdit.documentTitle() function will return the text from within HTML <title> 标签。

使用 QTextEdit 作为编辑器

All the information about using PySide.QtGui.QTextEdit as a display widget also applies here.

设置当前字符格式的属性采用 PySide.QtGui.QTextEdit.setFontItalic() , PySide.QtGui.QTextEdit.setFontWeight() , PySide.QtGui.QTextEdit.setFontUnderline() , PySide.QtGui.QTextEdit.setFontFamily() , PySide.QtGui.QTextEdit.setFontPointSize() , PySide.QtGui.QTextEdit.setTextColor() and PySide.QtGui.QTextEdit.setCurrentFont() . The current paragraph's alignment is set with PySide.QtGui.QTextEdit.setAlignment() .

文本选择的处理通过 PySide.QtGui.QTextCursor 类,提供创建选择、检索文本内容或删除选定的功能。可以检索对应用户可见光标的对象使用 PySide.QtGui.QTextEdit.textCursor() method. If you want to set a selection in PySide.QtGui.QTextEdit just create one on a PySide.QtGui.QTextCursor 对象然后使该光标成为可见光标使用 PySide.QtGui.QTextEdit.setTextCursor() . The selection can be copied to the clipboard with PySide.QtGui.QTextEdit.copy() , or cut to the clipboard with PySide.QtGui.QTextEdit.cut() . The entire text can be selected using PySide.QtGui.QTextEdit.selectAll() .

当光标被移动且底层格式化属性改变时, PySide.QtGui.QTextEdit.currentCharFormatChanged() signal is emitted to reflect the new attributes at the new cursor position.

PySide.QtGui.QTextEdit holds a PySide.QtGui.QTextDocument 对象,可以被检索使用 PySide.QtGui.QTextEdit.document() method. You can also set your own document object using PySide.QtGui.QTextEdit.setDocument() . PySide.QtGui.QTextDocument 发射 PySide.QtGui.QTextEdit.textChanged() signal if the text changes and it also provides a isModified() 函数,返回 true 若文本在加载或采用 false 作为自变量最后调用 setModified 后被修改。此外,它提供撤消和重做方法。

拖放

PySide.QtGui.QTextEdit also supports custom drag and drop behavior. By default, PySide.QtGui.QTextEdit will insert plain text, HTML and rich text when the user drops data of these MIME types onto a document. Reimplement PySide.QtGui.QTextEdit.canInsertFromMimeData() and PySide.QtGui.QTextEdit.insertFromMimeData() to add support for additional MIME types.

For example, to allow the user to drag and drop an image onto a PySide.QtGui.QTextEdit , you could the implement these functions in the following way:

def canInsertFromMimeData(source):
    if source.hasImage:
        return True
    else:
        return QTextEdit.canInsertFromMimeData(source)
											

通过返回 true 添加对图像 MIME 类型的支持。对于所有其它 MIME 类型,使用默认实现。

void TextEdit::insertFromMimeData( const QMimeData *source )
{
    if (source->hasImage())
    {
        QImage image = qvariant_cast<QImage>(source->imageData());
        QTextCursor cursor = this->textCursor();
        QTextDocument *document = this->document();
        document->addResource(QTextDocument::ImageResource, QUrl("image"), image);
        cursor.insertImage("image");
    }
}
										

解包图像从 PySide.QtCore.QVariant 保持通过 MIME 源并把它作为资源插入文档。

编辑键绑定

为编辑而实现的键绑定列表:

Keypresses Action
Backspace 删除光标左侧字符。
Delete 删除光标右侧字符。
Ctrl+C 把选中文本拷贝到剪贴板。
Ctrl+Insert 把选中文本拷贝到剪贴板。
Ctrl+K 删除到行尾。
Ctrl+V 把剪贴板文本粘贴到文本编辑中。
Shift+Insert 把剪贴板文本粘贴到文本编辑中。
Ctrl+X 删除选中文本并把它拷贝到剪贴板。
Shift+Delete 删除选中文本并把它拷贝到剪贴板。
Ctrl+Z 撤消上一操作。
Ctrl+Y 重做上一操作。
Left 左移光标一字符。
Ctrl+Left 把光标左移一单词。
Right 右移光标一字符。
Ctrl+Right 把光标右移一单词。
Up 上移光标一行。
Down 下移光标一行。
PageUp 把光标上移一页。
PageDown 把光标下移一页。
首页 把光标移到行开头。
Ctrl+Home 把光标移到文本开头。
End 把光标移到行尾。
Ctrl+End 把光标移到文本末尾。
Alt+Wheel 水平卷动页面 (Wheel 是鼠标滚轮)。

要选择 (标记) 文本,在按住 Shift 键的同时按下某一移动按键,例如, Shift+Right 将选择右侧字符,而 Shift+Ctrl+Right 将选择右侧单词,等等。

另请参阅

PySide.QtGui.QTextDocument PySide.QtGui.QTextCursor 应用程序范例 句法高亮范例 富文本处理

class PySide.QtGui. QTextEdit ( [ parent=None ] )
class PySide.QtGui. QTextEdit ( text [ , parent=None ] )
参数:

构造空 PySide.QtGui.QTextEdit 采用父级 parent .

构造 PySide.QtGui.QTextEdit 采用父级 parent 。文本编辑将显示文本 text 。文本被解释成 HTML。

PySide.QtGui.QTextEdit. AutoFormattingFlag
常量 描述
QTextEdit.AutoNone 不做任何自动格式化。
QTextEdit.AutoBulletList Automatically create bullet lists (e.g. when the user enters an asterisk (‘*') in the left most column, or presses Enter in an existing list item.
QTextEdit.AutoAll 应用所有自动格式。目前仅支持自动项目符号列表。
PySide.QtGui.QTextEdit. LineWrapMode
常量 描述
QTextEdit.NoWrap  
QTextEdit.WidgetWidth  
QTextEdit.FixedPixelWidth  
QTextEdit.FixedColumnWidth  
PySide.QtGui.QTextEdit. acceptRichText ( )
返回类型: PySide.QtCore.bool

This property holds whether the text edit accepts rich text insertions by the user.

当此特性被设为 false 时,文本编辑将只接受来自用户的纯文本输入。例如:透过剪贴板或拖放。

此特性默认为 true。

PySide.QtGui.QTextEdit. alignment ( )
返回类型: PySide.QtCore.Qt.Alignment

返回当前段落的对齐方式。

PySide.QtGui.QTextEdit. anchorAt ( pos )
参数: pos PySide.QtCore.QPoint
返回类型: unicode

返回锚点引用在位置 pos ,或空字符串若该点不存在锚点。

PySide.QtGui.QTextEdit. append ( text )
参数: text – unicode

追加新段落采用 text 到文本编辑末尾。

注意

The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor.

PySide.QtGui.QTextEdit. autoFormatting ( )
返回类型: PySide.QtGui.QTextEdit.AutoFormatting

This property holds the enabled set of auto formatting features.

值可以是值的任何组合在 QTextEdit.AutoFormattingFlag 枚举。默认为 AutoNone 。选取 AutoAll 以启用所有自动格式化。

目前,唯一提供的自动格式化特征是 AutoBulletList ;未来版本的 Qt 可能提供更多。

PySide.QtGui.QTextEdit. canInsertFromMimeData ( source )
参数: source PySide.QtCore.QMimeData
返回类型: PySide.QtCore.bool

This function returns true if the contents of the MIME data object, specified by source , can be decoded and inserted into the document. It is called for example when during a drag operation the mouse enters this widget and it is necessary to determine whether it is possible to accept the drag and drop operation.

重新实现此函数以启用对额外 MIME 类型的拖放支持。

PySide.QtGui.QTextEdit. canPaste ( )
返回类型: PySide.QtCore.bool

返回是否可以把文本从剪贴板粘贴到 textedit。

PySide.QtGui.QTextEdit. clear ( )

删除文本编辑中的所有文本。

Note that the undo/redo history is cleared by this function.

PySide.QtGui.QTextEdit. copy ( )

把任何选中文本拷贝到剪贴板。

PySide.QtGui.QTextEdit. copyAvailable ( b )
参数: b PySide.QtCore.bool
PySide.QtGui.QTextEdit. createMimeDataFromSelection ( )
返回类型: PySide.QtCore.QMimeData

This function returns a new MIME data object to represent the contents of the text edit's current selection. It is called when the selection needs to be encapsulated into a new PySide.QtCore.QMimeData object; for example, when a drag and drop operation is started, or when data is copyied to the clipboard.

If you reimplement this function, note that the ownership of the returned PySide.QtCore.QMimeData object is passed to the caller. The selection can be retrieved by using the PySide.QtGui.QTextEdit.textCursor() 函数。

PySide.QtGui.QTextEdit. createStandardContextMenu ( )
返回类型: PySide.QtGui.QMenu

此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击文本编辑时。它被调用从默认 PySide.QtGui.QTextEdit.contextMenuEvent() 处理程序。弹出菜单的所有权被转移给调用者。

推荐使用 createStandardContextMenu( PySide.QtCore.QPoint ) 版本,启用用户点击位置敏感动作。

PySide.QtGui.QTextEdit. createStandardContextMenu ( position )
参数: position PySide.QtCore.QPoint
返回类型: PySide.QtGui.QMenu

此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击文本编辑时。它被调用从默认 PySide.QtGui.QTextEdit.contextMenuEvent() handler and it takes the position of where the mouse click was. This can enable actions that are sensitive to the position where the user clicked. The popup menu's ownership is transferred to the caller.

PySide.QtGui.QTextEdit. currentCharFormat ( )
返回类型: PySide.QtGui.QTextCharFormat

返回插入新文本时使用的字符格式。

PySide.QtGui.QTextEdit. currentCharFormatChanged ( format )
参数: format PySide.QtGui.QTextCharFormat
PySide.QtGui.QTextEdit. currentFont ( )
返回类型: PySide.QtGui.QFont

返回当前格式的字体。

PySide.QtGui.QTextEdit. cursorForPosition ( pos )
参数: pos PySide.QtCore.QPoint
返回类型: PySide.QtGui.QTextCursor

返回 PySide.QtGui.QTextCursor 在位置 pos (在视口坐标中)。

PySide.QtGui.QTextEdit. cursorPositionChanged ( )
PySide.QtGui.QTextEdit. cursorRect ( )
返回类型: PySide.QtCore.QRect

返回包括文本编辑光标的矩形 (在视口坐标中)。

PySide.QtGui.QTextEdit. cursorRect ( cursor )
参数: cursor PySide.QtGui.QTextCursor
返回类型: PySide.QtCore.QRect

返回矩形 (在视口坐标中) 包括 cursor .

PySide.QtGui.QTextEdit. cursorWidth ( )
返回类型: PySide.QtCore.int

此特性指定光标的宽度 (以像素为单位)。默认值为 1。

PySide.QtGui.QTextEdit. cut ( )

把选中文本拷贝到剪贴板,并将其从文本编辑中删除。

若没有选中文本,什么都不发生。

PySide.QtGui.QTextEdit. document ( )
返回类型: PySide.QtGui.QTextDocument

返回指向底层文档的指针。

PySide.QtGui.QTextEdit. documentTitle ( )
返回类型: unicode

This property holds the title of the document parsed from the text..

默认情况下,对于新创建的空文档,此特性包含空字符串。

PySide.QtGui.QTextEdit. ensureCursorVisible ( )

通过卷动文本编辑确保光标是可见的,若有必要。

PySide.QtGui.QTextEdit. extraSelections ( )
返回类型:

返回先前设置的额外选定。

PySide.QtGui.QTextEdit. find ( exp [ , options=0 ] )
参数:
  • exp – unicode
  • options PySide.QtGui.QTextDocument.FindFlags
返回类型:

PySide.QtCore.bool

PySide.QtGui.QTextEdit. fontFamily ( )
返回类型: unicode

返回当前格式的字体系列。

PySide.QtGui.QTextEdit. fontItalic ( )
返回类型: PySide.QtCore.bool

Returns true if the font of the current format is italic; otherwise returns false.

PySide.QtGui.QTextEdit. fontPointSize ( )
返回类型: PySide.QtCore.qreal

返回当前格式字体的点尺寸。

PySide.QtGui.QTextEdit. fontUnderline ( )
返回类型: PySide.QtCore.bool

Returns true if the font of the current format is underlined; otherwise returns false.

PySide.QtGui.QTextEdit. fontWeight ( )
返回类型: PySide.QtCore.int

返回当前格式的字体权重。

PySide.QtGui.QTextEdit. insertFromMimeData ( source )
参数: source PySide.QtCore.QMimeData

This function inserts the contents of the MIME data object, specified by source , into the text edit at the current cursor position. It is called whenever text is inserted as the result of a clipboard paste operation, or when the text edit accepts data from a drag and drop operation.

重新实现此函数以启用对额外 MIME 类型的拖放支持。

PySide.QtGui.QTextEdit. insertHtml ( text )
参数: text – unicode

方便槽,插入 text which is assumed to be of html formatting at the current cursor position.

相当于:

edit.textCursor().insertHtml(fragment)
												

注意

When using this function with a style sheet, the style sheet will only apply to the current block in the document. In order to apply a style sheet throughout a document, use QTextDocument.setDefaultStyleSheet() 代替。

PySide.QtGui.QTextEdit. insertPlainText ( text )
参数: text – unicode

方便槽,插入 text 在当前光标位置。

它相当于

edit.textCursor().insertText(text)
												
PySide.QtGui.QTextEdit. isReadOnly ( )
返回类型: PySide.QtCore.bool

This property holds whether the text edit is read-only.

在只读文本编辑中,用户只能导航文本和选择文本;修改文本是不可能的。

此特性默认为 false。

PySide.QtGui.QTextEdit. isUndoRedoEnabled ( )
返回类型: PySide.QtCore.bool

This property holds whether undo and redo are enabled.

Users are only able to undo or redo actions if this property is true, and if there is an action that can be undone (or redone).

PySide.QtGui.QTextEdit. lineWrapColumnOrWidth ( )
返回类型: PySide.QtCore.int

This property holds the position (in pixels or columns depending on the wrap mode) where text will be wrapped.

若换行模式为 FixedPixelWidth , the value is the number of pixels from the left edge of the text edit at which text should be wrapped. If the wrap mode is FixedColumnWidth , the value is the column number (in character columns) from the left edge of the text edit at which text should be wrapped.

默认情况下,此特性包含 0 值。

PySide.QtGui.QTextEdit. lineWrapMode ( )
返回类型: PySide.QtGui.QTextEdit.LineWrapMode

This property holds the line wrap mode.

默认模式为 WidgetWidth 促使单词在文本编辑右边缘换行。换行发生在空白处,保持整个单词完整。若想要换行发生在单词内,使用 PySide.QtGui.QTextEdit.setWordWrapMode() . If you set a wrap mode of FixedPixelWidth or FixedColumnWidth 还应调用 PySide.QtGui.QTextEdit.setLineWrapColumnOrWidth() with the width you want.

PySide.QtGui.QTextEdit. loadResource ( type , name )
参数:
返回类型:

object

加载指定资源通过给定 type and name .

This function is an extension of QTextDocument.loadResource() .

PySide.QtGui.QTextEdit. mergeCurrentCharFormat ( modifier )
参数: modifier PySide.QtGui.QTextCharFormat

Merges the properties specified in modifier into the current character format by calling QTextCursor::mergeCharFormat on the editor's cursor. If the editor has a selection then the properties of modifier are directly applied to the selection.

PySide.QtGui.QTextEdit. moveCursor ( operation [ , mode=QTextCursor.MoveAnchor ] )
参数:
PySide.QtGui.QTextEdit. overwriteMode ( )
返回类型: PySide.QtCore.bool

This property holds whether text entered by the user will overwrite existing text.

As with many text editors, the text editor widget can be configured to insert or overwrite existing text with new text entered by the user.

If this property is true, existing text is overwritten, character-for-character by new text; otherwise, text is inserted at the cursor position, displacing existing text.

By default, this property is false (new text does not overwrite existing text).

PySide.QtGui.QTextEdit. paste ( )

把剪贴板文本粘贴到文本编辑当前光标位置处。

若剪贴板中没有文本,什么都不发生。

To change the behavior of this function, i.e. to modify what PySide.QtGui.QTextEdit can paste and how it is being pasted, reimplement the virtual PySide.QtGui.QTextEdit.canInsertFromMimeData() and PySide.QtGui.QTextEdit.insertFromMimeData() 函数。

PySide.QtGui.QTextEdit. print_ ( printer )
参数: printer PySide.QtGui.QPrinter

方便函数以将文本编辑文档打印到给定 printer . This is equivalent to calling the print method on the document directly except that this function also supports QPrinter.Selection as print range.

另请参阅

QTextDocument.print()

PySide.QtGui.QTextEdit. redo ( )

重做上一操作。

If there is no operation to redo, i.e. there is no redo step in the undo/redo history, nothing happens.

PySide.QtGui.QTextEdit. redoAvailable ( b )
参数: b PySide.QtCore.bool
PySide.QtGui.QTextEdit. scrollToAnchor ( name )
参数: name – unicode

Scrolls the text edit so that the anchor with the given name is visible; does nothing if the name is empty, or is already visible, or isn't found.

PySide.QtGui.QTextEdit. selectAll ( )

选择所有文本。

PySide.QtGui.QTextEdit. selectionChanged ( )
PySide.QtGui.QTextEdit. setAcceptRichText ( accept )
参数: accept PySide.QtCore.bool

This property holds whether the text edit accepts rich text insertions by the user.

当此特性被设为 false 时,文本编辑将只接受来自用户的纯文本输入。例如:透过剪贴板或拖放。

此特性默认为 true。

PySide.QtGui.QTextEdit. setAlignment ( a )
参数: a PySide.QtCore.Qt.Alignment
PySide.QtGui.QTextEdit. setAutoFormatting ( features )
参数: features PySide.QtGui.QTextEdit.AutoFormatting

This property holds the enabled set of auto formatting features.

值可以是值的任何组合在 QTextEdit.AutoFormattingFlag 枚举。默认为 AutoNone 。选取 AutoAll 以启用所有自动格式化。

目前,唯一提供的自动格式化特征是 AutoBulletList ;未来版本的 Qt 可能提供更多。

PySide.QtGui.QTextEdit. setCurrentCharFormat ( format )
参数: format PySide.QtGui.QTextCharFormat

把新文本插入时使用的字符格式设为 format 通过调用 QTextCursor.setCharFormat() on the editor's cursor. If the editor has a selection then the char format is directly applied to the selection.

PySide.QtGui.QTextEdit. setCurrentFont ( f )
参数: f PySide.QtGui.QFont

把当前格式的字体设为 f .

PySide.QtGui.QTextEdit. setCursorWidth ( width )
参数: width PySide.QtCore.int

此特性指定光标的宽度 (以像素为单位)。默认值为 1。

PySide.QtGui.QTextEdit. setDocument ( document )
参数: document PySide.QtGui.QTextDocument

Makes document the new document of the text editor.

注意

编辑器 不拥有文档的所有权 unless it is the document's parent object. The parent object of the provided document remains the owner of the object.

The editor does not delete the current document, even if it is a child of the editor.

PySide.QtGui.QTextEdit. setDocumentTitle ( title )
参数: title – unicode

This property holds the title of the document parsed from the text..

默认情况下,对于新创建的空文档,此特性包含空字符串。

PySide.QtGui.QTextEdit. setExtraSelections ( selections )
参数: selections
PySide.QtGui.QTextEdit. setFontFamily ( fontFamily )
参数: fontFamily – unicode

把当前格式的字体系列设为 fontFamily .

PySide.QtGui.QTextEdit. setFontItalic ( b )
参数: b PySide.QtCore.bool

italic is true, sets the current format to italic; otherwise sets the current format to non-italic.

PySide.QtGui.QTextEdit. setFontPointSize ( s )
参数: s PySide.QtCore.qreal

将当前格式的点尺寸设为 s .

注意:若 s is zero or negative, the behavior of this function is not defined.

PySide.QtGui.QTextEdit. setFontUnderline ( b )
参数: b PySide.QtCore.bool

underline is true, sets the current format to underline; otherwise sets the current format to non-underline.

PySide.QtGui.QTextEdit. setFontWeight ( w )
参数: w PySide.QtCore.int

Sets the font weight of the current format to the given weight , where the value used is in the range defined by the QFont.Weight 枚举。

PySide.QtGui.QTextEdit. setHtml ( text )
参数: text – unicode

此特性为文本编辑的文本提供到 HTML 的接口。

PySide.QtGui.QTextEdit.toHtml() returns the text of the text edit as html.

PySide.QtGui.QTextEdit.setHtml() changes the text of the text edit. Any previous text is removed and the undo/redo history is cleared. The input text is interpreted as rich text in html format.

注意

调用者有责任确保正确解码文本当 PySide.QtCore.QString containing HTML is created and passed to PySide.QtGui.QTextEdit.setHtml() .

默认情况下,对于新近创建的空文档,此特性包含用于描述没有本体文本的 HTML 4.0 文档文本。

另请参阅

支持的 HTML 子集 plainText()

PySide.QtGui.QTextEdit. setLineWrapColumnOrWidth ( w )
参数: w PySide.QtCore.int

This property holds the position (in pixels or columns depending on the wrap mode) where text will be wrapped.

若换行模式为 FixedPixelWidth , the value is the number of pixels from the left edge of the text edit at which text should be wrapped. If the wrap mode is FixedColumnWidth , the value is the column number (in character columns) from the left edge of the text edit at which text should be wrapped.

默认情况下,此特性包含 0 值。

PySide.QtGui.QTextEdit. setLineWrapMode ( mode )
参数: mode PySide.QtGui.QTextEdit.LineWrapMode

This property holds the line wrap mode.

默认模式为 WidgetWidth 促使单词在文本编辑右边缘换行。换行发生在空白处,保持整个单词完整。若想要换行发生在单词内,使用 PySide.QtGui.QTextEdit.setWordWrapMode() . If you set a wrap mode of FixedPixelWidth or FixedColumnWidth 还应调用 PySide.QtGui.QTextEdit.setLineWrapColumnOrWidth() with the width you want.

PySide.QtGui.QTextEdit. setOverwriteMode ( overwrite )
参数: overwrite PySide.QtCore.bool

This property holds whether text entered by the user will overwrite existing text.

As with many text editors, the text editor widget can be configured to insert or overwrite existing text with new text entered by the user.

If this property is true, existing text is overwritten, character-for-character by new text; otherwise, text is inserted at the cursor position, displacing existing text.

By default, this property is false (new text does not overwrite existing text).

PySide.QtGui.QTextEdit. setPlainText ( text )
参数: text – unicode

This property gets and sets the text editor's contents as plain text. Previous contents are removed and undo/redo history is reset when the property is set.

If the text edit has another content type, it will not be replaced by plain text if you call PySide.QtGui.QTextEdit.toPlainText() . The only exception to this is the non-break space, nbsp; , that will be converted into standard space.

默认情况下,对于没有内容的编辑器,此特性包含空字符串。

另请参阅

html()

PySide.QtGui.QTextEdit. setReadOnly ( ro )
参数: ro PySide.QtCore.bool

This property holds whether the text edit is read-only.

在只读文本编辑中,用户只能导航文本和选择文本;修改文本是不可能的。

此特性默认为 false。

PySide.QtGui.QTextEdit. setTabChangesFocus ( b )
参数: b PySide.QtCore.bool

此特性保持是否 Tab changes focus or is accepted as input.

In some occasions text edits should not allow the user to input tabulators or change indentation using the Tab key, as this breaks the focus chain. The default is false.

PySide.QtGui.QTextEdit. setTabStopWidth ( width )
参数: width PySide.QtCore.int

此特性保持 Tab (制表符) 停止宽度 (以像素为单位)。

默认情况下,此特性包含 80 像素的值。

PySide.QtGui.QTextEdit. setText ( text )
参数: text – unicode

设置文本编辑的 text . The text can be plain text or HTML and the text edit will try to guess the right format.

使用 PySide.QtGui.QTextEdit.setHtml() or PySide.QtGui.QTextEdit.setPlainText() directly to avoid text edit's guessing.

PySide.QtGui.QTextEdit. setTextBackgroundColor ( c )
参数: c PySide.QtGui.QColor

把当前格式的文本背景颜色设为 c .

PySide.QtGui.QTextEdit. setTextColor ( c )
参数: c PySide.QtGui.QColor

把当前格式的文本颜色设为 c .

PySide.QtGui.QTextEdit. setTextCursor ( cursor )
参数: cursor PySide.QtGui.QTextCursor

设置可见 cursor .

PySide.QtGui.QTextEdit. setTextInteractionFlags ( flags )
参数: flags PySide.QtCore.Qt.TextInteractionFlags

指定 Widget 应如何与用户输入交互。

默认值取决于 PySide.QtGui.QTextEdit 是只读或可编辑,且它是否为 PySide.QtGui.QTextBrowser or not.

PySide.QtGui.QTextEdit. setUndoRedoEnabled ( enable )
参数: enable PySide.QtCore.bool

This property holds whether undo and redo are enabled.

Users are only able to undo or redo actions if this property is true, and if there is an action that can be undone (or redone).

PySide.QtGui.QTextEdit. setWordWrapMode ( policy )
参数: policy PySide.QtGui.QTextOption.WrapMode
PySide.QtGui.QTextEdit. tabChangesFocus ( )
返回类型: PySide.QtCore.bool

此特性保持是否 Tab changes focus or is accepted as input.

In some occasions text edits should not allow the user to input tabulators or change indentation using the Tab key, as this breaks the focus chain. The default is false.

PySide.QtGui.QTextEdit. tabStopWidth ( )
返回类型: PySide.QtCore.int

此特性保持 Tab (制表符) 停止宽度 (以像素为单位)。

默认情况下,此特性包含 80 像素的值。

PySide.QtGui.QTextEdit. textBackgroundColor ( )
返回类型: PySide.QtGui.QColor

返回当前格式的文本背景颜色。

PySide.QtGui.QTextEdit. textChanged ( )
PySide.QtGui.QTextEdit. textColor ( )
返回类型: PySide.QtGui.QColor

返回当前格式的文本颜色。

PySide.QtGui.QTextEdit. textCursor ( )
返回类型: PySide.QtGui.QTextCursor

返回副本为 PySide.QtGui.QTextCursor 表示当前可见光标。注意:改变返回光标不影响 PySide.QtGui.QTextEdit ‘s cursor; use PySide.QtGui.QTextEdit.setTextCursor() to update the visible cursor.

PySide.QtGui.QTextEdit. textInteractionFlags ( )
返回类型: PySide.QtCore.Qt.TextInteractionFlags

指定 Widget 应如何与用户输入交互。

默认值取决于 PySide.QtGui.QTextEdit 是只读或可编辑,且它是否为 PySide.QtGui.QTextBrowser or not.

PySide.QtGui.QTextEdit. toHtml ( )
返回类型: unicode

此特性为文本编辑的文本提供到 HTML 的接口。

PySide.QtGui.QTextEdit.toHtml() returns the text of the text edit as html.

PySide.QtGui.QTextEdit.setHtml() changes the text of the text edit. Any previous text is removed and the undo/redo history is cleared. The input text is interpreted as rich text in html format.

注意

调用者有责任确保正确解码文本当 PySide.QtCore.QString containing HTML is created and passed to PySide.QtGui.QTextEdit.setHtml() .

默认情况下,对于新近创建的空文档,此特性包含用于描述没有本体文本的 HTML 4.0 文档文本。

另请参阅

支持的 HTML 子集 plainText()

PySide.QtGui.QTextEdit. toPlainText ( )
返回类型: unicode

This property gets and sets the text editor's contents as plain text. Previous contents are removed and undo/redo history is reset when the property is set.

If the text edit has another content type, it will not be replaced by plain text if you call PySide.QtGui.QTextEdit.toPlainText() . The only exception to this is the non-break space, nbsp; , that will be converted into standard space.

默认情况下,对于没有内容的编辑器,此特性包含空字符串。

另请参阅

html()

PySide.QtGui.QTextEdit. undo ( )

撤消上一操作。

若没有要撤消的操作 (即:撤消/重做历史中没有撤消步骤),什么都不发生。

PySide.QtGui.QTextEdit. undoAvailable ( b )
参数: b PySide.QtCore.bool
PySide.QtGui.QTextEdit. wordWrapMode ( )
返回类型: PySide.QtGui.QTextOption.WrapMode
PySide.QtGui.QTextEdit. zoomIn ( [ range=1 ] )
参数: range PySide.QtCore.int

Zooms in on the text by making the base font size range points larger and recalculating all font sizes to be the new size. This does not change the size of any images.

PySide.QtGui.QTextEdit. zoomOut ( [ range=1 ] )
参数: range PySide.QtCore.int

这是重载函数。

Zooms out on the text by making the base font size range points smaller and recalculating all font sizes to be the new size. This does not change the size of any images.