QTextEdit Class Reference

[QtGui module]

该的QTextEdit类提供用于编辑和显示两个平原和丰富的文本控件。More…

继承QAbstractScrollArea

通过继承QTextBrowser

Types

  • class **[AutoFormatting]($docs-index.htm)**
  • enum AutoFormattingFlag { AutoNone, AutoBulletList, AutoAll }
  • class **[ExtraSelection]($docs-index.htm)**
  • enum LineWrapMode { NoWrap, WidgetWidth, FixedPixelWidth, FixedColumnWidth }

Methods

  • __init__ (self, QWidget parent = None)
  • __init__ (self, QString text, QWidget parent = None)
  • bool acceptRichText (self)
  • Qt.Alignment alignment (self)
  • QString anchorAt (self, QPoint pos)
  • append (self, QString text)
  • AutoFormatting autoFormatting (self)
  • bool canInsertFromMimeData (self, QMimeData source)
  • bool canPaste (self)
  • changeEvent (self, QEvent e)
  • clear (self)
  • contextMenuEvent (self, QContextMenuEvent e)
  • copy (self)
  • QMimeData createMimeDataFromSelection (self)
  • QMenu createStandardContextMenu (self)
  • QMenu createStandardContextMenu (self, QPoint position)
  • QTextCharFormat currentCharFormat (self)
  • QFont currentFont (self)
  • QTextCursor cursorForPosition (self, QPoint pos)
  • QRect cursorRect (self, QTextCursor cursor)
  • QRect cursorRect (self)
  • int cursorWidth (self)
  • cut (self)
  • QTextDocument document (self)
  • QString documentTitle (self)
  • dragEnterEvent (self, QDragEnterEvent e)
  • dragLeaveEvent (self, QDragLeaveEvent e)
  • dragMoveEvent (self, QDragMoveEvent e)
  • dropEvent (self, QDropEvent e)
  • ensureCursorVisible (self)
  • bool event (self, QEvent e)
  • list-of-QTextEdit.ExtraSelection extraSelections (self)
  • bool find (self, QString exp, QTextDocument.FindFlags options = 0)
  • focusInEvent (self, QFocusEvent e)
  • bool focusNextPrevChild (self, bool next)
  • focusOutEvent (self, QFocusEvent e)
  • QString fontFamily (self)
  • bool fontItalic (self)
  • float fontPointSize (self)
  • bool fontUnderline (self)
  • int fontWeight (self)
  • inputMethodEvent (self, QInputMethodEvent)
  • QVariant inputMethodQuery (self, Qt.InputMethodQuery property)
  • insertFromMimeData (self, QMimeData source)
  • insertHtml (self, QString text)
  • insertPlainText (self, QString text)
  • bool isReadOnly (self)
  • bool isUndoRedoEnabled (self)
  • keyPressEvent (self, QKeyEvent e)
  • keyReleaseEvent (self, QKeyEvent e)
  • int lineWrapColumnOrWidth (self)
  • LineWrapMode lineWrapMode (self)
  • QVariant loadResource (self, int type, QUrl name)
  • mergeCurrentCharFormat (self, QTextCharFormat modifier)
  • mouseDoubleClickEvent (self, QMouseEvent e)
  • mouseMoveEvent (self, QMouseEvent e)
  • mousePressEvent (self, QMouseEvent e)
  • mouseReleaseEvent (self, QMouseEvent e)
  • moveCursor (self, QTextCursor.MoveOperation operation, QTextCursor.MoveMode mode = QTextCursor.MoveAnchor)
  • bool overwriteMode (self)
  • paintEvent (self, QPaintEvent e)
  • paste (self)
  • print (self, QPrinter printer)
  • print_ (self, QPrinter printer)
  • redo (self)
  • resizeEvent (self, QResizeEvent)
  • scrollContentsBy (self, int dx, int dy)
  • scrollToAnchor (self, QString name)
  • selectAll (self)
  • setAcceptRichText (self, bool accept)
  • setAlignment (self, Qt.Alignment a)
  • setAutoFormatting (self, AutoFormatting features)
  • setCurrentCharFormat (self, QTextCharFormat format)
  • setCurrentFont (self, QFont f)
  • setCursorWidth (self, int width)
  • setDocument (self, QTextDocument document)
  • setDocumentTitle (self, QString title)
  • setExtraSelections (self, list-of-QTextEdit.ExtraSelection selections)
  • setFontFamily (self, QString fontFamily)
  • setFontItalic (self, bool b)
  • setFontPointSize (self, float s)
  • setFontUnderline (self, bool b)
  • setFontWeight (self, int w)
  • setHtml (self, QString text)
  • setLineWrapColumnOrWidth (self, int w)
  • setLineWrapMode (self, LineWrapMode mode)
  • setOverwriteMode (self, bool overwrite)
  • setPlainText (self, QString text)
  • setReadOnly (self, bool ro)
  • setTabChangesFocus (self, bool b)
  • setTabStopWidth (self, int width)
  • setText (self, QString text)
  • setTextBackgroundColor (self, QColor c)
  • setTextColor (self, QColor c)
  • setTextCursor (self, QTextCursor cursor)
  • setTextInteractionFlags (self, Qt.TextInteractionFlags flags)
  • setUndoRedoEnabled (self, bool enable)
  • setWordWrapMode (self, QTextOption.WrapMode policy)
  • showEvent (self, QShowEvent)
  • bool tabChangesFocus (self)
  • int tabStopWidth (self)
  • QColor textBackgroundColor (self)
  • QColor textColor (self)
  • QTextCursor textCursor (self)
  • Qt.TextInteractionFlags textInteractionFlags (self)
  • timerEvent (self, QTimerEvent e)
  • QString toHtml (self)
  • QString toPlainText (self)
  • undo (self)
  • wheelEvent (self, QWheelEvent e)
  • QTextOption.WrapMode wordWrapMode (self)
  • zoomIn (self, int range = 1)
  • zoomOut (self, int range = 1)

Qt Signals

  • void copyAvailable (bool)
  • void currentCharFormatChanged (const QTextCharFormat&)
  • void cursorPositionChanged ()
  • void redoAvailable (bool)
  • void selectionChanged ()
  • void textChanged ()
  • void undoAvailable (bool)

Detailed Description

该的QTextEdit类提供用于编辑和显示两个平原和丰富的文本控件。

Introduction and Concepts

的QTextEdit是一种先进的所见即所得的浏览器/编辑器,支持丰富的文本格式使用HTML风格的标籤。这是优化处理大型文件,并快速响应用户输入。

QTextEdit一起工作的段落和字符。一个段落是一个格式化字符串,它是自动换行以适应窗口部件的宽度。通过阅读纯文本时,默认情况下,有一个换行符表示一个段落。文档包含零个或多个段落。段落中的单词排列按照段落的对齐方式。段落是由硬换行符分隔。一个段内的每个字符具有其自己的属性,例如,字体和颜色。

的QTextEdit可以显示图像,列表和表格。如果文本太大无法查看文本编辑的视口内,滚动条就会出现。文本编辑可以加载纯文本和HTML文件( HTML 3.2的子集和4 ) 。

如果你只是需要显示一小块富文本使用QLabel

在Qt的富文本支持旨在提供一种快速,便携,高效的方式来合理的在线帮助工具添加到应用程序,并提供丰富的文本编辑器的基础。如果您发现该HTML支持不足,为您的需求,您可以考虑使用QtWebKit,它提供了一个全功能的Web浏览器控件。

鼠标光标的上一个的QTextEdit的形状是Qt.IBeamCursor在默认情况下。它可以通过改变该viewport( )的游标属性。

Using QTextEdit as a Display Widget

的QTextEdit可以显示一个大的HTML子集,包括表格和图像。

全文载或更换使用setHtml(),它会删除任何现有文本,并与所传递的文本替换它setHtml( )调用。如果你打电话setHtml( )与传统的HTML ,然后调用toHtml( ) ,返回的文本可能有不同的标记,但会呈现相同的。整个文本可以被删除clear( ) 。

文本本身可以使用插入的QTextCursor类或者使用的方便功能insertHtml( )insertPlainText( )append()或paste( ) 。QTextCursor也能像插入表格或列表的复杂对象插入到文档中,它处理创建的选择和应用更改选定的文本。

默认情况下,文本编辑换行的空白,以适应文本编辑窗口部件。该setLineWrapMode( )函数是用来指定你想要的那种换行的,或NoWrap如果你不希望任何包装。通话setLineWrapMode( )来设置一个固定像素宽度FixedPixelWidth,或字符列(例如80列)FixedColumnWidth与指定的像素或列setLineWrapColumnOrWidth( ) 。如果您使用自动换行到Widget的宽度WidgetWidth,您可以指定是否要与打破空白或任何地方setWordWrapMode( ) 。

find( )函数可以用来查找和选择文本中给定的字符串。

如果你想限制在一个的QTextEdit段的总数,例如它往往是在日志查看器有用,那么你可以使用QTextDocument的maximumBlockCount属性的。

Read-only Key Bindings

当QTextEdit一起使用只读的键绑定仅限于导航和文字可能只用鼠标进行选择:

Keypresses Action
Up Moves one line up.
Down Moves one line down.
Left Moves one character to the left.
Right Moves one character to the right.
PageUp Moves one (viewport) page up.
PageDown Moves one (viewport) page down.
Home Moves to the beginning of the text.
End Moves to the end of the text.
Alt+Wheel Scrolls the page horizontally (the Wheel is the mouse wheel).
Ctrl+Wheel Zooms the text.
Ctrl+A Selects all text.

文本编辑可能能够提供一些元信息。例如,本documentTitle( )函数将来自内部的HTML返回文本<title>标籤。

Using QTextEdit as an Editor

所有有关使用的QTextEdit作为一个显示插件的信息也适用于这里。

目前char格式的属性设置setFontItalic( )setFontWeight( )setFontUnderline( )setFontFamily( )setFontPointSize( )setTextColor()和setCurrentFont( ) 。当前段落的对齐方式设置与setAlignment( ) 。

选择文本是由处理QTextCursor类,它用于创建选择,检索的文本内容或删除选项提供的功能。你可以检索与用户可见的光标使用相对应的对象textCursor()方法。如果你想设置一个选择使用QTextEdit只需要建立一个上一个QTextCursor对象,然后使该游标使用游标可见setTextCursor( ) 。选择可以复制到剪贴板copy( ) ,或剪切到剪贴板cut( ) 。整个文本可以使用选择selectAll( ) 。

当光标被移动和底层的格式属性的变化,currentCharFormatChanged()信号被发射,以反映新的光标位置处的新的属性。

的QTextEdit持有QTextDocument这可以使用被检索对象的document()方法。您也可以使用设置自己的文档对象setDocument( ) 。QTextDocument发出textChanged( )信号,如果文本的变化,它也提供了一个isModified( )函数,如果文本已经被修改,因为它是在加载或自上次调用SetModified之用False作为参数,该参数将返回True 。此外,它还提供了撤销和重做的方法。

Drag and Drop

的QTextEdit还支持自定义拖放行为。默认情况下,会的QTextEdit当用户删除这些MIME类型的数据到一个文档中插入纯文本, HTML和RTF 。重新实现canInsertFromMimeData()和insertFromMimeData()来添加额外的MIME类型的支持。

例如,为了允许用户拖放图像投影到的QTextEdit ,你可以在以下面的方式实现这些功能:

  1. bool TextEdit.canInsertFromMimeData( const [QMimeData]($docs-qmimedata.html) *source ) const
  2. {
  3. if (source->hasImage())
  4. return true;
  5. else
  6. return QTextEdit.canInsertFromMimeData(source);
  7. }

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

  1. void TextEdit.insertFromMimeData( const [QMimeData]($docs-qmimedata.html) *source )
  2. {
  3. if (source->hasImage())
  4. {
  5. [QImage](qimage.html) image = qvariant_cast<[QImage](qimage.html)>(source->imageData());
  6. [QTextCursor]($docs-qtextcursor.html) cursor = this->textCursor();
  7. [QTextDocument]($docs-qtextdocument.html) *document = this->document();
  8. document->addResource([QTextDocument]($docs-qtextdocument.html).ImageResource, [QUrl](qurl.html)("image"), image);
  9. cursor.insertImage("image");
  10. }
  11. }

我们解压缩图像从QVariant由MIME源举行,并将其插入到文档中作为一个资源。

Editing Key Bindings

这是实施进行编辑键绑定列表:

Keypresses Action
Backspace Deletes the character to the left of the cursor.
Delete Deletes the character to the right of the cursor.
Ctrl+C Copy the selected text to the clipboard.
Ctrl+Insert Copy the selected text to the clipboard.
Ctrl+K Deletes to the end of the line.
Ctrl+V Pastes the clipboard text into text edit.
Shift+Insert Pastes the clipboard text into text edit.
Ctrl+X Deletes the selected text and copies it to the clipboard.
Shift+Delete Deletes the selected text and copies it to the clipboard.
Ctrl+Z Undoes the last operation.
Ctrl+Y Redoes the last operation.
Left Moves the cursor one character to the left.
Ctrl+Left Moves the cursor one word to the left.
Right Moves the cursor one character to the right.
Ctrl+Right Moves the cursor one word to the right.
Up Moves the cursor one line up.
Down Moves the cursor one line down.
PageUp Moves the cursor one page up.
PageDown Moves the cursor one page down.
Home Moves the cursor to the beginning of the line.
Ctrl+Home Moves the cursor to the beginning of the text.
End Moves the cursor to the end of the line.
Ctrl+End Moves the cursor to the end of the text.
Alt+Wheel Scrolls the page horizontally (the Wheel is the mouse wheel).

选择(标记)的文本按住Shift键的同时按下按键的运动之一,例如,Shift+Right将选择的字符的权利,Shift+Ctrl+Right将选择字的右边,等。


Type Documentation

  1. QTextEdit.AutoFormattingFlag
Constant Value Description
QTextEdit.AutoNone 0 不要做任何自动格式化。
QTextEdit.AutoBulletList 0x00000001 自动创建项目符号列表(例如,当用户输入一个星号( “*” )在最左边的列,或压在现有列表项中输入。
QTextEdit.AutoAll 0xffffffff 适用于所有的自动格式化。目前只有自动符号列表的支持。

该自动格式化类型是一个typedef为QFlags\u003cAutoFormattingFlag\u003e 。它存储AutoFormattingFlag值的或组合。

  1. QTextEdit.LineWrapMode
Constant Value
QTextEdit.NoWrap 0
QTextEdit.WidgetWidth 1
QTextEdit.FixedPixelWidth 2
QTextEdit.FixedColumnWidth 3

Method Documentation

  1. QTextEdit.__init__ (self, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个空QTextEdit与父parent

  1. QTextEdit.__init__ (self, QString text, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个QTextEdit与父parent。文本编辑将显示的文本text。该文本被解释为HTML 。

  1. bool QTextEdit.acceptRichText (self)
  1. Qt.Alignment QTextEdit.alignment (self)

[

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

]($docs-index.htm)

See also setAlignment( ) 。

  1. QString QTextEdit.anchorAt (self, QPoint pos)

返回锚的位置处的参考pos,或者如果没有锚存在于该点一个空字符串。

  1. QTextEdit.append (self, QString text)

追加一个新的段落text到文本编辑的末尾。

Note:追加了新的段落将具有相同的字符格式和块格式作为当前段中,光标的位置确定。

See also currentCharFormat()和QTextCursor.blockFormat( ) 。

  1. AutoFormatting QTextEdit.autoFormatting (self)

[

  1. bool QTextEdit.canInsertFromMimeData (self, QMimeData source)

这个函数返回True,如果MIME数据对象,由指定的内容source,可以被解码并插入到文档中。它被称为例如,当拖动操作期间鼠标进入这个小部件,并确定是否可以接受该拖放操作是必要的。

重新实现这项功能,让拖放额外的MIME类型的支持。

  1. bool QTextEdit.canPaste (self)

返回是否文本可以从剪贴板粘贴到文本编辑。

这个函数中引入了Qt 4.2中。

  1. QTextEdit.changeEvent (self, QEvent e)

]($docs-index.htm)

从重新实现QWidget.changeEvent( ) 。

  1. QTextEdit.clear (self)

这种方法也是一个Qt槽与C + +的签名void clear()

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

请注意,撤消/重做历史是由这个函数清除。

See also cut( )setPlainText()和setHtml( ) 。

  1. QTextEdit.contextMenuEvent (self, QContextMenuEvent e)

从重新实现QWidget.contextMenuEvent( ) 。

显示与标准上下文菜单创建createStandardContextMenu( ) 。

如果您不希望文本编辑有个上下文菜单,可以设置其contextMenuPolicyQt.NoContextMenu。如果你想自定义右键菜单,重新实现这个函数。如果你想扩展标准上下文菜单,重新实现这个函数,调用createStandardContextMenu()和extend菜单返回。

有关事件的信息传递中event对象。

  1. void MyTextEdit.contextMenuEvent([QContextMenuEvent](qcontextmenuevent.html) *event)
  2. {
  3. [QMenu]($docs-qmenu.html) *menu = createStandardContextMenu();
  4. menu->addAction(tr("My Menu Item"));
  5. //...
  6. menu->exec(event->globalPos());
  7. delete menu;
  8. }
  1. QTextEdit.copy (self)

这种方法也是一个Qt槽与C + +的签名void copy()

副本中的任何选定的文本复制到剪贴板。

See also copyAvailable( ) 。

  1. QMimeData QTextEdit.createMimeDataFromSelection (self)

这个函数返回一个新的MIME数据对象来表示文本编辑的当前选择的内容。当选择需要被封装到一个新的被称为QMimeData对象,例如,当启动一个拖放操作,或当数据被copyied到剪贴板。

如果重新实现此功能,请注意,返回的所有权QMimeData对象被传递给调用者。的选择可以通过使用检索到的textCursor()函数。

  1. QMenu QTextEdit.createStandardContextMenu (self)

这个函数创建当用户点击文本编辑用鼠标右键其显示在标准上下文菜单。它是从默认称为contextMenuEvent()处理。在弹出菜单的所有权被传递给调用者。

我们建议您使用createStandardContextMenu (QPoint)版本而不是这将使那些到用户点击敏感的动作。

  1. QMenu QTextEdit.createStandardContextMenu (self, QPoint position)

这个函数创建当用户点击文本编辑用鼠标右键其显示在标准上下文菜单。它是从默认称为contextMenuEvent( )处理程序,它需要的position哪里的鼠标点击是。这可以使那些到用户点击的位置敏感的动作。在弹出菜单的所有权被传递给调用者。

此功能被引入Qt的4.4 。

  1. QTextCharFormat QTextEdit.currentCharFormat (self)

[

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

]($docs-qtextcharformat.html)

See also setCurrentCharFormat( ) 。

  1. QFont QTextEdit.currentFont (self)

[

返回当前格式的字体。

]($docs-qfont.html)

See also setCurrentFont( )setFontFamily()和setFontPointSize( ) 。

  1. QTextCursor QTextEdit.cursorForPosition (self, QPoint pos)

返回QTextCursor在位置pos(在视口坐标) 。

  1. QRect QTextEdit.cursorRect (self, QTextCursor cursor)

[

返回一个矩形(在视区坐标) ,其中包括cursor

]($docs-qrect.html)

  1. QRect QTextEdit.cursorRect (self)

[

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

  1. int QTextEdit.cursorWidth (self)
  1. QTextEdit.cut (self)

这种方法也是一个Qt槽与C + +的签名void cut()

将所选文本复制到剪贴板,并从文本编辑删除它。

如果没有选中的文本没有任何反应。

]($docs-qrect.html)

See also copy()和paste( ) 。

  1. QTextDocument QTextEdit.document (self)

[

返回一个指针,指向底层的文件。

]($docs-qtextdocument.html)

See also setDocument( ) 。

  1. QString QTextEdit.documentTitle (self)
  1. QTextEdit.dragEnterEvent (self, QDragEnterEvent e)

从重新实现QWidget.dragEnterEvent( ) 。

  1. QTextEdit.dragLeaveEvent (self, QDragLeaveEvent e)

从重新实现QWidget.dragLeaveEvent( ) 。

  1. QTextEdit.dragMoveEvent (self, QDragMoveEvent e)

从重新实现QWidget.dragMoveEvent( ) 。

  1. QTextEdit.dropEvent (self, QDropEvent e)

从重新实现QWidget.dropEvent( ) 。

  1. QTextEdit.ensureCursorVisible (self)

确保光标是在必要时滚动文本编辑可见。

  1. bool QTextEdit.event (self, QEvent e)
  1. list-of-QTextEdit.ExtraSelection QTextEdit.extraSelections (self)

返回以前设置额外的选择。

这个函数中引入了Qt 4.2中。

See also setExtraSelections( ) 。

  1. bool QTextEdit.find (self, QString exp, QTextDocument.FindFlags options = 0)

查找字符串的下一个出现,exp,使用给定的options。返回True如果exp被发现并改变光标选择匹配,否则返回False 。

  1. QTextEdit.focusInEvent (self, QFocusEvent e)

从重新实现QWidget.focusInEvent( ) 。

  1. bool QTextEdit.focusNextPrevChild (self, bool next)

从重新实现QWidget.focusNextPrevChild( ) 。

  1. QTextEdit.focusOutEvent (self, QFocusEvent e)

从重新实现QWidget.focusOutEvent( ) 。

  1. QString QTextEdit.fontFamily (self)

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

See also setFontFamily( )setCurrentFont()和setFontPointSize( ) 。

  1. bool QTextEdit.fontItalic (self)

返回True如果当前格式的字体是斜体,否则返回False 。

See also setFontItalic( ) 。

  1. float QTextEdit.fontPointSize (self)

返回当前格式的字体的磅值。

See also setFontFamily( )setCurrentFont()和setFontPointSize( ) 。

  1. bool QTextEdit.fontUnderline (self)

返回True如果当前格式的字体底线,否则返回False 。

See also setFontUnderline( ) 。

  1. int QTextEdit.fontWeight (self)

返回当前格式的字体粗细。

See also setFontWeight( )setCurrentFont( )setFontPointSize()和QFont.Weight

  1. QTextEdit.inputMethodEvent (self, QInputMethodEvent)

从重新实现QWidget.inputMethodEvent( ) 。

  1. QVariant QTextEdit.inputMethodQuery (self, Qt.InputMethodQuery property)

从重新实现QWidget.inputMethodQuery( ) 。

  1. QTextEdit.insertFromMimeData (self, QMimeData source)

该功能可以插入的MIME数据对象的内容,由指定的source,到在当前光标位置的文本编辑。它被调用时插入文本作为一个剪贴板粘贴操作的结果,或者当文本编辑接受来自拖拽数据和拖放操作。

重新实现这项功能,让拖放额外的MIME类型的支持。

  1. QTextEdit.insertHtml (self, QString text)

这种方法也是一个Qt槽与C + +的签名void insertHtml(const QString&)

便利的插槽,插入text这被认为是HTML格式在当前光标位置。

它等价于:

  1. edit->textCursor().insertHtml(fragment);

Note:使用此功能时使用样式表,样式表只适用于文档中的当前块。为了对整个文档应用样式表,使用QTextDocument.setDefaultStyleSheet( )来代替。

  1. QTextEdit.insertPlainText (self, QString text)

这种方法也是一个Qt槽与C + +的签名void insertPlainText(const QString&)

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

它相当于

  1. edit->textCursor().insertText(text);
  1. bool QTextEdit.isReadOnly (self)
  1. bool QTextEdit.isUndoRedoEnabled (self)
  1. QTextEdit.keyPressEvent (self, QKeyEvent e)

从重新实现QWidget.keyPressEvent( ) 。

  1. QTextEdit.keyReleaseEvent (self, QKeyEvent e)

从重新实现QWidget.keyReleaseEvent( ) 。

  1. int QTextEdit.lineWrapColumnOrWidth (self)
  1. LineWrapMode QTextEdit.lineWrapMode (self)

[

  1. QVariant QTextEdit.loadResource (self, int type, QUrl name)

加载给定指定的资源typename

]($docs-qtextedit.html#LineWrapMode-enum)

这个函数是一个扩展QTextDocument.loadResource( ) 。

See also QTextDocument.loadResource( ) 。

  1. QTextEdit.mergeCurrentCharFormat (self, QTextCharFormat modifier)

在合并中指定的属性modifier成通过在编辑器的光标调用QTextCursor.mergeCharFormat当前字符格式。如果编辑器有一个选择了属性modifier直接施加到选择。

See also QTextCursor.mergeCharFormat( ) 。

  1. QTextEdit.mouseDoubleClickEvent (self, QMouseEvent e)

从重新实现QWidget.mouseDoubleClickEvent( ) 。

  1. QTextEdit.mouseMoveEvent (self, QMouseEvent e)

从重新实现QWidget.mouseMoveEvent( ) 。

  1. QTextEdit.mousePressEvent (self, QMouseEvent e)

从重新实现QWidget.mousePressEvent( ) 。

  1. QTextEdit.mouseReleaseEvent (self, QMouseEvent e)

从重新实现QWidget.mouseReleaseEvent( ) 。

  1. QTextEdit.moveCursor (self, QTextCursor.MoveOperation operation, QTextCursor.MoveMode mode = QTextCursor.MoveAnchor)

通过执行给定的移动光标operation

If mode is QTextCursor.KeepAnchor,光标选择它移动到文本上。这是当他们按住Shift键并移动光标,光标键,用户达到相同的效果。

这个函数中引入了Qt 4.2中。

See also QTextCursor.movePosition( ) 。

  1. bool QTextEdit.overwriteMode (self)
  1. QTextEdit.paintEvent (self, QPaintEvent e)

从重新实现QWidget.paintEvent( ) 。

此事件处理程序可以在子类来接收传入paint事件重新实现event。它通常是不必要的重写本函数中的一个子类QTextEdit

Warning:相关文本文档不能从这个函数的重新实现中修改。

  1. QTextEdit.paste (self)

这种方法也是一个Qt槽与C + +的签名void paste()

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

如果在剪贴板中没有文本没有任何反应。

要更改此函数的行为,即要修改什么QTextEdit可以粘贴以及它是如何被粘贴,重新实现虚canInsertFromMimeData()和insertFromMimeData()函数。

See also cut()和copy( ) 。

  1. QTextEdit.print (self, QPrinter printer)

方便的功能,文本编辑的文档打印到指定的printer。这等同于调用print方法上的文件直接,除了这个功能也支持QPrinter.Selection作为打印范围。

此功能被引入Qt的4.3 。

See also QTextDocument.print( ) 。

  1. QTextEdit.print_ (self, QPrinter printer)

方便的功能,文本编辑的文档打印到指定的printer。这等同于调用print方法上的文件直接,除了这个功能也支持QPrinter.Selection作为打印范围。

此功能被引入Qt的4.3 。

See also QTextDocument.print( ) 。

  1. QTextEdit.redo (self)

这种方法也是一个Qt槽与C + +的签名void redo()

重做上次操作。

如果没有操作可以恢复,也就是说,在撤消/重做历史没有恢复步骤,没有任何反应。

这个函数中引入了Qt 4.2中。

See also undo( ) 。

  1. QTextEdit.resizeEvent (self, QResizeEvent)

从重新实现QWidget.resizeEvent( ) 。

  1. QTextEdit.scrollContentsBy (self, int dx, int dy)

从重新实现QAbstractScrollArea.scrollContentsBy( ) 。

  1. QTextEdit.scrollToAnchor (self, QString name)

这种方法也是一个Qt槽与C + +的签名void scrollToAnchor(const QString&)

滚动文本编辑,以便与锚定name可见,什么也不做,如果name是空的,或者已经是可见的,或者是没有找到。

  1. QTextEdit.selectAll (self)

这种方法也是一个Qt槽与C + +的签名void selectAll()

选择所有文本。

See also copy( )cut()和textCursor( ) 。

  1. QTextEdit.setAcceptRichText (self, bool accept)
  1. QTextEdit.setAlignment (self, Qt.Alignment a)

这种方法也是一个Qt槽与C + +的签名void setAlignment(Qt::Alignment)

设置当前段落的对齐方式a。有效的路线是Qt.AlignLeftQt.AlignRightQt.AlignJustifyQt.AlignCenter(其中中心水平方向)。

See also alignment( ) 。

  1. QTextEdit.setAutoFormatting (self, AutoFormatting features)
  1. QTextEdit.setCurrentCharFormat (self, QTextCharFormat format)

设置要插入新的文本时可以使用的字符格式format通过调用QTextCursor.setCharFormat( )在编辑器的光标。如果编辑器有一个选择,则该字符格式被直接施加到选择。

See also currentCharFormat( ) 。

  1. QTextEdit.setCurrentFont (self, QFont f)

这种方法也是一个Qt槽与C + +的签名void setCurrentFont(const QFont&)

设置当前格式的字体f

See also currentFont( )setFontPointSize()和setFontFamily( ) 。

  1. QTextEdit.setCursorWidth (self, int width)
  1. QTextEdit.setDocument (self, QTextDocument document)

品牌document在文本编辑器中的新文件。

Note:编辑器does not take ownership of the document除非它是文档的父对象。所提供的文档的父对象仍然是对象的所有者。

该编辑器不会删除当前文件,哪怕是编辑器的一个孩子。

See also document( ) 。

  1. QTextEdit.setDocumentTitle (self, QString title)
  1. QTextEdit.setExtraSelections (self, list-of-QTextEdit.ExtraSelection selections)

此功能允许暂时标记文档中的某些区域用给定的颜色,指定为selections。这可以是有用的,例如在一个节目的编辑器来标记文本的一整行与给定的背景颜色来表示一个断点的存在。

这个函数中引入了Qt 4.2中。

See also QTextEdit.ExtraSelectionextraSelections( ) 。

  1. QTextEdit.setFontFamily (self, QString fontFamily)

这种方法也是一个Qt槽与C + +的签名void setFontFamily(const QString&)

设置当前格式的字体家族fontFamily

See also fontFamily()和setCurrentFont( ) 。

  1. QTextEdit.setFontItalic (self, bool b)

这种方法也是一个Qt槽与C + +的签名void setFontItalic(bool)

If italic诚然,设置当前格式为斜体,否则设置当前格式为非斜体。

See also fontItalic( ) 。

  1. QTextEdit.setFontPointSize (self, float s)

这种方法也是一个Qt槽与C + +的签名void setFontPointSize(qreal)

设置当前格式的点大小为s

注意,如果s是零或负数,此函数的行为没有定义。

See also fontPointSize( )setCurrentFont()和setFontFamily( ) 。

  1. QTextEdit.setFontUnderline (self, bool b)

这种方法也是一个Qt槽与C + +的签名void setFontUnderline(bool)

If underline诚然,设置当前格式强调,否则设置当前格式是没有下划线。

See also fontUnderline( ) 。

  1. QTextEdit.setFontWeight (self, int w)

这种方法也是一个Qt槽与C + +的签名void setFontWeight(int)

设置当前格式的字体粗细来定weight其中使用的值是在由规定的范围QFont.Weight枚举。

See also fontWeight( )setCurrentFont()和setFontFamily( ) 。

  1. QTextEdit.setHtml (self, QString text)

这种方法也是一个Qt槽与C + +的签名void setHtml(const QString&)

  1. QTextEdit.setLineWrapColumnOrWidth (self, int w)
  1. QTextEdit.setLineWrapMode (self, LineWrapMode mode)
  1. QTextEdit.setOverwriteMode (self, bool overwrite)
  1. QTextEdit.setPlainText (self, QString text)

这种方法也是一个Qt槽与C + +的签名void setPlainText(const QString&)

  1. QTextEdit.setReadOnly (self, bool ro)
  1. QTextEdit.setTabChangesFocus (self, bool b)
  1. QTextEdit.setTabStopWidth (self, int width)
  1. QTextEdit.setText (self, QString text)

这种方法也是一个Qt槽与C + +的签名void setText(const QString&)

设置文本编辑的text。该文本可以是纯文本或HTML和文本编辑会尝试猜测正确的格式。

使用setHtml()或setPlainText( )直接以避免文本编辑的猜测。

这个函数中引入了Qt 4.2中。

See also text( )toPlainText()和toHtml( ) 。

  1. QTextEdit.setTextBackgroundColor (self, QColor c)

这种方法也是一个Qt槽与C + +的签名void setTextBackgroundColor(const QColor&)

设置当前格式的文本背景颜色c

此功能被引入Qt的4.4 。

See also textBackgroundColor( ) 。

  1. QTextEdit.setTextColor (self, QColor c)

这种方法也是一个Qt槽与C + +的签名void setTextColor(const QColor&)

设置当前格式的文本颜色c

See also textColor( ) 。

  1. QTextEdit.setTextCursor (self, QTextCursor cursor)

设置可见cursor

See also textCursor( ) 。

  1. QTextEdit.setTextInteractionFlags (self, Qt.TextInteractionFlags flags)
  1. QTextEdit.setUndoRedoEnabled (self, bool enable)
  1. QTextEdit.setWordWrapMode (self, QTextOption.WrapMode policy)
  1. QTextEdit.showEvent (self, QShowEvent)

从重新实现QWidget.showEvent( ) 。

  1. bool QTextEdit.tabChangesFocus (self)
  1. int QTextEdit.tabStopWidth (self)
  1. QColor QTextEdit.textBackgroundColor (self)

[

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

此功能被引入Qt的4.4 。

]($docs-qcolor.html)

See also setTextBackgroundColor( ) 。

  1. QColor QTextEdit.textColor (self)

[

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

]($docs-qcolor.html)

See also setTextColor( ) 。

  1. QTextCursor QTextEdit.textCursor (self)

返回的副本QTextCursor表示当前可见的光标。请注意,在返回的指针变化不影响QTextEdit的游标;使用setTextCursor( )来更新可见的光标。

See also setTextCursor( ) 。

  1. Qt.TextInteractionFlags QTextEdit.textInteractionFlags (self)

[

  1. QTextEdit.timerEvent (self, QTimerEvent e)
  1. QString QTextEdit.toHtml (self)
  1. QString QTextEdit.toPlainText (self)
  1. QTextEdit.undo (self)

这种方法也是一个Qt槽与C + +的签名void undo()

撤消上一个操作。

如果没有操作可以撤销,也就是说,在撤消/恢复历史中没有撤销一步,没有任何反应。

这个函数中引入了Qt 4.2中。

]($docs-index.htm)

See also redo( ) 。

  1. QTextEdit.wheelEvent (self, QWheelEvent e)

从重新实现QWidget.wheelEvent( ) 。

  1. QTextOption.WrapMode QTextEdit.wordWrapMode (self)

[

  1. QTextEdit.zoomIn (self, int range = 1)

这种方法也是一个Qt槽与C + +的签名void zoomIn(int = 1)

放大了的文本通过把基本字体大小range大点并且重新计算所有字体大小是新的大小。这不会改变任何图片的大小。

]($docs-qtextoption.html#WrapMode-enum)

See also zoomOut( ) 。

  1. QTextEdit.zoomOut (self, int range = 1)

这种方法也是一个Qt槽与C + +的签名void zoomOut(int = 1)

这是一个重载函数。

缩小上通过把基本字体大小的文本range小点并且重新计算所有字体大小是新的大小。这不会改变任何图片的大小。

See also zoomIn( ) 。


Qt Signal Documentation

  1. void copyAvailable (bool)

这是该信号的默认超载。

当选择文本或文本编辑取消选择,这个信号被发射。

当选择文本这个信号将被发射yes设置为True 。如果没有文本被选中,或者如果选定的文本被取消选择这个信号被发射与yes设置为False 。

If yes是真的,那么copy( )可以用来选择复制到剪贴板。如果yes为False,则copy( )什么也不做。

See also selectionChanged( ) 。

  1. void currentCharFormatChanged (const QTextCharFormat&)

这是该信号的默认超载。

这个信号被发射,如果当前字符格式发生了变化,例如所造成的光标位置的改变。

新格式f

See also setCurrentCharFormat( ) 。

  1. void cursorPositionChanged ()

这是该信号的默认超载。

这个信号被发射时的光标的位置改变。

  1. void redoAvailable (bool)

这是该信号的默认超载。

这个信号被发射时重做操作变得可用(available为True)或不可用(available是假的) 。

  1. void selectionChanged ()

这是该信号的默认超载。

这个信号被发射时的选择改变。

See also copyAvailable( ) 。

  1. void textChanged ()

这是该信号的默认超载。

这个信号被发射时该文档的内容更改,例如,当文本被插入或删除,或格式化时被应用。

  1. void undoAvailable (bool)

这是该信号的默认超载。

这个信号被发射时撤销操作变得可用(available为True)或不可用(available是假的) 。