QTextEdit 类

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

头: #include <QTextEdit>
qmake: QT += widgets
继承: QAbstractScrollArea
继承者:

QTextBrowser

公共类型

class ExtraSelection
flags AutoFormatting
enum AutoFormattingFlag { AutoNone, AutoBulletList, AutoAll }
enum LineWrapMode { NoWrap, WidgetWidth, FixedPixelWidth, FixedColumnWidth }

特性

公共函数

QTextEdit (QWidget * parent = Q_NULLPTR)
QTextEdit (const QString & text , QWidget * parent = Q_NULLPTR)
virtual ~QTextEdit ()
bool acceptRichText () const
Qt::Alignment alignment () const
QString anchorAt (const QPoint & pos ) const
AutoFormatting autoFormatting () const
bool canPaste () const
QMenu * createStandardContextMenu ()
QMenu * createStandardContextMenu (const QPoint & position )
QTextCharFormat currentCharFormat () const
QFont currentFont () const
QTextCursor cursorForPosition (const QPoint & pos ) const
QRect cursorRect (const QTextCursor & cursor ) const
QRect cursorRect () const
int cursorWidth () const
QTextDocument * document () const
QString documentTitle () const
void ensureCursorVisible ()
QList<ExtraSelection> extraSelections () const
bool find (const QString & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())
bool find (const QRegExp & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())
QString fontFamily () const
bool fontItalic () const
qreal fontPointSize () const
bool fontUnderline () const
int fontWeight () const
bool isReadOnly () const
bool isUndoRedoEnabled () const
int lineWrapColumnOrWidth () const
LineWrapMode lineWrapMode () const
virtual QVariant loadResource (int type , const QUrl & name )
void mergeCurrentCharFormat (const QTextCharFormat & modifier )
void moveCursor (QTextCursor::MoveOperation operation , QTextCursor::MoveMode mode = QTextCursor::MoveAnchor)
bool overwriteMode () const
QString placeholderText () const
void print (QPagedPaintDevice * printer ) const
void setAcceptRichText (bool accept )
void setAutoFormatting (AutoFormatting features )
void setCurrentCharFormat (const QTextCharFormat & format )
void setCursorWidth (int width )
void setDocument (QTextDocument * document )
void setDocumentTitle (const QString & title )
void setExtraSelections (const QList<ExtraSelection> & selections )
void setLineWrapColumnOrWidth (int w )
void setLineWrapMode (LineWrapMode mode )
void setOverwriteMode (bool overwrite )
void setPlaceholderText (const QString & placeholderText )
void setReadOnly (bool ro )
void setTabChangesFocus (bool b )
void setTabStopWidth (int width )
void setTextCursor (const QTextCursor & cursor )
void setTextInteractionFlags (Qt::TextInteractionFlags flags )
void setUndoRedoEnabled (bool enable )
void setWordWrapMode (QTextOption::WrapMode policy )
bool tabChangesFocus () const
int tabStopWidth () const
QColor textBackgroundColor () const
QColor textColor () const
QTextCursor textCursor () const
Qt::TextInteractionFlags textInteractionFlags () const
QString toHtml () const
QString toPlainText () const
QTextOption::WrapMode wordWrapMode () const

重实现公共函数

virtual QVariant inputMethodQuery (Qt::InputMethodQuery property ) const

公共槽

void append (const QString & text )
void clear ()
void copy ()
void cut ()
void insertHtml (const QString & text )
void insertPlainText (const QString & text )
void paste ()
void redo ()
void scrollToAnchor (const QString & name )
void selectAll ()
void setAlignment (Qt::Alignment a )
void setCurrentFont (const QFont & f )
void setFontFamily (const QString & fontFamily )
void setFontItalic (bool italic )
void setFontPointSize (qreal s )
void setFontUnderline (bool underline )
void setFontWeight (int weight )
void setHtml (const QString & text )
void setPlainText (const QString & text )
void setText (const QString & text )
void setTextBackgroundColor (const QColor & c )
void setTextColor (const QColor & c )
void undo ()
void zoomIn (int range = 1)
void zoomOut (int range = 1)

信号

void copyAvailable (bool yes )
void currentCharFormatChanged (const QTextCharFormat & f )
void cursorPositionChanged ()
void redoAvailable (bool available )
void selectionChanged ()
void textChanged ()
void undoAvailable (bool available )

保护函数

virtual bool canInsertFromMimeData (const QMimeData * source ) const
virtual QMimeData * createMimeDataFromSelection () const
virtual void insertFromMimeData (const QMimeData * source )

重实现保护函数

virtual void changeEvent (QEvent * e )
virtual void contextMenuEvent (QContextMenuEvent * event )
virtual void dragEnterEvent (QDragEnterEvent * e )
virtual void dragLeaveEvent (QDragLeaveEvent * e )
virtual void dragMoveEvent (QDragMoveEvent * e )
virtual void dropEvent (QDropEvent * e )
virtual void focusInEvent (QFocusEvent * e )
virtual bool focusNextPrevChild (bool next )
virtual void focusOutEvent (QFocusEvent * e )
virtual void inputMethodEvent (QInputMethodEvent * e )
virtual void keyPressEvent (QKeyEvent * e )
virtual void keyReleaseEvent (QKeyEvent * e )
virtual void mouseDoubleClickEvent (QMouseEvent * e )
virtual void mouseMoveEvent (QMouseEvent * e )
virtual void mousePressEvent (QMouseEvent * e )
virtual void mouseReleaseEvent (QMouseEvent * e )
virtual void paintEvent (QPaintEvent * event )
virtual void resizeEvent (QResizeEvent * e )
virtual void scrollContentsBy (int dx , int dy )
virtual void showEvent ( QShowEvent * )
virtual void wheelEvent (QWheelEvent * e )

额外继承成员

详细描述

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

介绍和概念

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.

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.

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 rich text files. Rich text is described using a subset of HTML 4 markup, refer to the 支持的 HTML 子集 页面,了解更多信息。

若仅仅需要显示小段富文本使用 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 Qt WebKit , which provides a full-featured web browser widget.

The shape of the mouse cursor on a QTextEdit is Qt::IBeamCursor 默认情况下。它可以被改变透过 viewport () 的光标特性。

使用 QTextEdit 作为显示 Widget

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

设置或替代文本使用 setHtml () 删除并替换任何现有文本,采用将文本传入 setHtml () 调用。若调用 setHtml () 采用传统 HTML,然后调用 toHtml (),返回文本可能有不同标记,但渲染是相同的。可以删除整个文本采用 clear ().

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

默认情况下,文本编辑在空白处自动换行以拟合在文本编辑 Widget 中。 setLineWrapMode () 函数用于指定想要的换行种类,或 NoWrap 若不想要任何换行。调用 setLineWrapMode () 去设置固定像素宽度 FixedPixelWidth ,或字符列 (如:80 列) FixedColumnWidth 按指定像素或列数采用 setLineWrapColumnOrWidth ()。若使用自动换行到 Widget 的宽度 WidgetWidth ,可以指定是在空白处断开还是在任何地方断开采用 setWordWrapMode ().

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

If you want to limit the total number of paragraphs in a QTextEdit , as for example it is often useful in a log viewer, then you can use QTextDocument 的 maximumBlockCount 特性为此。

只读键绑定

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

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

文本编辑可能能够提供一些元信息。例如, documentTitle () 函数将返回文本从 HTML <title> 标签。

注意: 缩放 HTML 文档才工作,若字体大小未被设为固定尺寸。

使用 QTextEdit 作为编辑器

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

设置当前字符格式的属性采用 setFontItalic (), setFontWeight (), setFontUnderline (), setFontFamily (), setFontPointSize (), setTextColor () 和 setCurrentFont ()。设置当前段落的对齐方式采用 setAlignment ().

文本选择的处理通过 QTextCursor 类,提供创建选择、检索文本内容或删除选定的功能。可以检索对应用户可见光标的对象使用 textCursor () method. If you want to set a selection in QTextEdit just create one on a QTextCursor 对象然后使该光标成为可见光标使用 setTextCursor ()。选定可以被拷贝到剪贴板采用 copy (),或剪切到剪贴板采用 cut ()。可以选择整个文本使用 selectAll ().

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

textChanged () 信号被发射每当文本改变时 (作为结果源于 setText () 或透过编辑器本身)。

QTextEdit holds a QTextDocument 对象,可以被检索使用 document () 方法。还可以设置自己的文档对象使用 setDocument ().

QTextDocument 提供 isModified() 函数,返回 true 若文本在加载或采用 false 作为自变量最后调用 setModified 后被修改。此外,它提供撤消和重做方法。

拖放

QTextEdit also supports custom drag and drop behavior. By default, QTextEdit will insert plain text, HTML and rich text when the user drops data of these MIME types onto a document. Reimplement canInsertFromMimeData () 和 insertFromMimeData () 以添加对额外 MIME 类型的支持。

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

bool TextEdit::canInsertFromMimeData( const QMimeData *source ) const
{
    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");
    }
}
					

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

编辑键绑定

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

按键 动作
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 将选择右侧单词,等等。

另请参阅 QTextDocument , QTextCursor , 应用程序范例 , 句法高亮范例 ,和 富文本处理 .

成员类型文档编制

enum QTextEdit:: AutoFormattingFlag
flags QTextEdit:: AutoFormatting

常量 描述
QTextEdit::AutoNone 0 不做任何自动格式化。
QTextEdit::AutoBulletList 0x00000001 自动创建项目符号列表 (如:当用户在最左列键入 * 星号,或在现有列表项中按 Enter 键)。
QTextEdit::AutoAll 0xffffffff 应用所有自动格式。目前仅支持自动项目符号列表。

AutoFormatting 类型是 typedef 对于 QFlags <AutoFormattingFlag>。它存储 AutoFormattingFlag 值的 OR 组合。

enum QTextEdit:: LineWrapMode

常量
QTextEdit::NoWrap 0
QTextEdit::WidgetWidth 1
QTextEdit::FixedPixelWidth 2
QTextEdit::FixedColumnWidth 3

特性文档编制

acceptRichText : bool

此特性保持文本编辑是否接受由用户插入的富文本

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

此特性默认为 true。

该特性在 Qt 4.1 引入。

访问函数:

bool acceptRichText () const
void setAcceptRichText (bool accept )

autoFormatting : AutoFormatting

此特性保持自动格式化特征的启用设置

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

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

访问函数:

AutoFormatting autoFormatting () const
void setAutoFormatting (AutoFormatting features )

cursorWidth : int

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

该特性在 Qt 4.2 引入。

访问函数:

int cursorWidth () const
void setCursorWidth (int width )

document : QTextDocument *

此特性保持文本编辑器的底层文档。

注意: 编辑器 不拥有文档的所有权 除非它是文档的父级对象。提供文档的父级对象仍是对象的所有者。若先前赋值的文档是编辑器的子级,就将它删除。

访问函数:

QTextDocument * document () const
void setDocument (QTextDocument * document )

documentTitle : QString

此特性保持剖析自文本的文档标题。

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

访问函数:

QString documentTitle () const
void setDocumentTitle (const QString & title )

html : QString

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

toHtml() 以 HTML 形式返回文本编辑的文本。

setHtml() 更改文本编辑文本。移除任何先前文本和清零撤消/重做历史。输入文本被解释为 html 格式富文本。

注意: 调用者有责任确保正确解码文本当 QString 包含的 HTML 被创建并传递给 setHtml() 时。

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

访问函数:

QString toHtml () const
void setHtml (const QString & text )

通知程序信号:

void textChanged ()

另请参阅 支持的 HTML 子集 and plainText .

lineWrapColumnOrWidth : int

此特性保持文本换行位置 (以像素或列为单位,从属换行模式)

若换行模式为 FixedPixelWidth ,值是从文本编辑左边缘开始 (文本应在哪里换行) 的像素数。若换行模式为 FixedColumnWidth ,值是从文本编辑左边缘开始 (文本应在哪里换行) 的列号 (以字符列为单位)。

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

访问函数:

int lineWrapColumnOrWidth () const
void setLineWrapColumnOrWidth (int w )

另请参阅 lineWrapMode .

lineWrapMode : LineWrapMode

此特性保持换行模式

默认模式为 WidgetWidth 促使单词在文本编辑右边缘换行。换行发生在空白处,保持整个单词完整。若想要换行发生在单词内,使用 setWordWrapMode ()。若将换行模式设为 FixedPixelWidth or FixedColumnWidth 还应调用 setLineWrapColumnOrWidth () 采用想要的宽度。

访问函数:

LineWrapMode lineWrapMode () const
void setLineWrapMode (LineWrapMode mode )

另请参阅 lineWrapColumnOrWidth .

overwriteMode : bool

此特性保持由用户键入的文本是否覆盖现有文本

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.

若此特性为 true , existing text is overwritten, character-for-character by new text; otherwise, text is inserted at the cursor position, displacing existing text.

默认情况下此特性为 false (新文本不覆写现有文本)。

该特性在 Qt 4.1 引入。

访问函数:

bool overwriteMode () const
void setOverwriteMode (bool overwrite )

placeholderText : QString

此特性保持编辑器占位符文本

设置此特性将使编辑器显示变灰占位符文本只要 document () 为空。

默认情况下,此特性包含空字符串。

该特性在 Qt 5.2 引入。

访问函数:

QString placeholderText () const
void setPlaceholderText (const QString & placeholderText )

另请参阅 document ().

plainText : QString

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 toPlainText (). The only exception to this is the non-break space, nbsp; , that will be converted into standard space.

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

该特性在 Qt 4.3 引入。

访问函数:

QString toPlainText () const
void setPlainText (const QString & text )

另请参阅 html .

readOnly : bool

此特性保持文本编辑是否为只读

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

此特性默认为 false。

访问函数:

bool isReadOnly () const
void setReadOnly (bool ro )

tabChangesFocus : bool

此特性保持是否 Tab 改变聚焦或接受作为输入

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.

访问函数:

bool tabChangesFocus () const
void setTabChangesFocus (bool b )

tabStopWidth : int

This property holds the tab stop width in pixels

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

该特性在 Qt 4.1 引入。

访问函数:

int tabStopWidth () const
void setTabStopWidth (int width )

textInteractionFlags : Qt::TextInteractionFlags

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

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

该特性在 Qt 4.2 引入。

访问函数:

Qt::TextInteractionFlags textInteractionFlags () const
void setTextInteractionFlags (Qt::TextInteractionFlags flags )

undoRedoEnabled : bool

此特性保持是否撤消和重做被启用

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

访问函数:

bool isUndoRedoEnabled () const
void setUndoRedoEnabled (bool enable )

wordWrapMode : QTextOption::WrapMode

此特性保持模式 QTextEdit 会使用,当按单词换行文本时

默认情况下,此特性被设为 QTextOption::WrapAtWordBoundaryOrAnywhere .

访问函数:

QTextOption::WrapMode wordWrapMode () const
void setWordWrapMode (QTextOption::WrapMode policy )

另请参阅 QTextOption::WrapMode .

成员函数文档编制

QTextEdit:: QTextEdit ( QWidget * parent = Q_NULLPTR)

构造空的 QTextEdit 采用父级 parent .

QTextEdit:: QTextEdit (const QString & text , QWidget * parent = Q_NULLPTR)

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

[virtual] QTextEdit:: ~QTextEdit ()

析构函数。

Qt::Alignment QTextEdit:: alignment () const

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

另请参阅 setAlignment ().

QString QTextEdit:: anchorAt (const QPoint & pos ) const

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

[slot] void QTextEdit:: append (const QString & text )

追加新段落采用 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.

另请参阅 currentCharFormat () 和 QTextCursor::blockFormat ().

[virtual protected] bool QTextEdit:: canInsertFromMimeData (const QMimeData * source ) const

此函数返回 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 类型的拖放支持。

bool QTextEdit:: canPaste () const

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

该函数在 Qt 4.2 引入。

[virtual protected] void QTextEdit:: changeEvent ( QEvent * e )

重实现自 QWidget::changeEvent ().

[slot] void QTextEdit:: clear ()

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

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

另请参阅 cut (), setPlainText (),和 setHtml ().

[virtual protected] void QTextEdit:: contextMenuEvent ( QContextMenuEvent * event )

重实现自 QWidget::contextMenuEvent ().

展示标准上下文菜单,创建采用 createStandardContextMenu ().

If you do not want the text edit to have a context menu, you can set its contextMenuPolicy to Qt::NoContextMenu 。若想要定制上下文菜单,重实现此函数。若想要扩展标准上下文菜单,重实现此函数,调用 createStandardContextMenu () 并扩展返回的菜单。

Information about the event is passed in the event 对象。

void MyTextEdit::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = createStandardContextMenu();
    menu->addAction(tr("My Menu Item"));
    //...
    menu->exec(event->globalPos());
    delete menu;
}
					

[slot] void QTextEdit:: copy ()

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

另请参阅 copyAvailable ().

[signal] void QTextEdit:: copyAvailable ( bool yes )

此信号被发射当在文本编辑中选择或取消选择文本时。

当有文本被选中时,此信号会被发射采用 yes 设为 true。若没有文本被选中或选中文本被取消选择,此信号被发射采用 yes 设为 false。

yes 为 True 则 copy () 可以用于把选定拷贝到剪贴板。若 yes 为 false 则 copy () 什么都不做。

另请参阅 selectionChanged ().

[virtual protected] QMimeData *QTextEdit:: createMimeDataFromSelection () const

此函数返回表示文本编辑当前选定内容的新的 MIME 数据对象。它被调用当需要将选定封装成新的 QMimeData 对象;例如,当开始拖放操作或将数据拷贝到剪贴板时。

若重实现此函数,注意,所有权对于返回的 QMimeData 对象被传递给调用者。可以检索选定通过使用 textCursor () 函数。

QMenu *QTextEdit:: createStandardContextMenu ()

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

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

QMenu *QTextEdit:: createStandardContextMenu (const QPoint & position )

此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击文本编辑时。它被调用从默认 contextMenuEvent () 处理程序,且它获取 position 在文档坐标中 (当鼠标点击时)。这可以启用用户点击位置敏感动作。弹出菜单的所有权被转移给调用者。

该函数在 Qt 4.4 引入。

QTextCharFormat QTextEdit:: currentCharFormat () const

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

另请参阅 setCurrentCharFormat ().

[signal] void QTextEdit:: currentCharFormatChanged (const QTextCharFormat & f )

此信号被发射,若当前字符格式已改变 (例如:通过光标位置的变化导致)。

新的格式为 f .

另请参阅 setCurrentCharFormat ().

QFont QTextEdit:: currentFont () const

返回当前格式的字体。

另请参阅 setCurrentFont (), setFontFamily (),和 setFontPointSize ().

QTextCursor QTextEdit:: cursorForPosition (const QPoint & pos ) const

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

[signal] void QTextEdit:: cursorPositionChanged ()

此信号被发射每当光标位置改变时。

QRect QTextEdit:: cursorRect (const QTextCursor & cursor ) const

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

QRect QTextEdit:: cursorRect () const

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

[slot] void QTextEdit:: cut ()

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

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

另请参阅 copy () 和 paste ().

[virtual protected] void QTextEdit:: dragEnterEvent ( QDragEnterEvent * e )

重实现自 QWidget::dragEnterEvent ().

[virtual protected] void QTextEdit:: dragLeaveEvent ( QDragLeaveEvent * e )

重实现自 QWidget::dragLeaveEvent ().

[virtual protected] void QTextEdit:: dragMoveEvent ( QDragMoveEvent * e )

重实现自 QWidget::dragMoveEvent ().

[virtual protected] void QTextEdit:: dropEvent ( QDropEvent * e )

重实现自 QWidget::dropEvent ().

void QTextEdit:: ensureCursorVisible ()

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

QList < ExtraSelection > QTextEdit:: extraSelections () const

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

该函数在 Qt 4.2 引入。

另请参阅 setExtraSelections ().

bool QTextEdit:: find (const QString & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())

查找字符串的下一出现 exp ,使用给定 options 。返回 true if exp 被发现且更改光标到选择匹配;否则返回 false .

bool QTextEdit:: find (const QRegExp & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())

这是重载函数。

查找匹配正则表达式的下一出现 exp ,使用给定 options QTextDocument::FindCaseSensitively 选项被忽略对于此重载,使用 QRegExp::caseSensitivity 代替。

返回 true 若找到匹配并把光标更改为选择匹配;否则返回 false .

该函数在 Qt 5.3 引入。

[virtual protected] void QTextEdit:: focusInEvent ( QFocusEvent * e )

重实现自 QWidget::focusInEvent ().

[virtual protected] bool QTextEdit:: focusNextPrevChild ( bool next )

重实现自 QWidget::focusNextPrevChild ().

[virtual protected] void QTextEdit:: focusOutEvent ( QFocusEvent * e )

重实现自 QWidget::focusOutEvent ().

QString QTextEdit:: fontFamily () const

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

另请参阅 setFontFamily (), setCurrentFont (),和 setFontPointSize ().

bool QTextEdit:: fontItalic () const

返回 true 若当前格式的字体是斜体;否则返回 false。

另请参阅 setFontItalic ().

qreal QTextEdit:: fontPointSize () const

返回当前格式的字体点大小。

另请参阅 setFontFamily (), setCurrentFont (),和 setFontPointSize ().

bool QTextEdit:: fontUnderline () const

返回 true 若当前格式字体带下划线;否则返回 false。

另请参阅 setFontUnderline ().

int QTextEdit:: fontWeight () const

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

另请参阅 setFontWeight (), setCurrentFont (), setFontPointSize (),和 QFont::Weight .

[virtual protected] void QTextEdit:: inputMethodEvent ( QInputMethodEvent * e )

重实现自 QWidget::inputMethodEvent ().

[virtual] QVariant QTextEdit:: inputMethodQuery ( Qt::InputMethodQuery property ) const

重实现自 QWidget::inputMethodQuery ().

[virtual protected] void QTextEdit:: insertFromMimeData (const QMimeData * source )

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 类型的拖放支持。

[slot] void QTextEdit:: insertHtml (const QString & text )

方便槽插入 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 () 代替。

[slot] void QTextEdit:: insertPlainText (const QString & text )

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

它相当于

edit->textCursor().insertText(text);
					

[virtual protected] void QTextEdit:: keyPressEvent ( QKeyEvent * e )

重实现自 QWidget::keyPressEvent ().

[virtual protected] void QTextEdit:: keyReleaseEvent ( QKeyEvent * e )

重实现自 QWidget::keyReleaseEvent ().

[virtual] QVariant QTextEdit:: loadResource ( int type , const QUrl & name )

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

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

另请参阅 QTextDocument::loadResource ().

void QTextEdit:: mergeCurrentCharFormat (const QTextCharFormat & modifier )

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.

另请参阅 QTextCursor::mergeCharFormat ().

[virtual protected] void QTextEdit:: mouseDoubleClickEvent ( QMouseEvent * e )

重实现自 QWidget::mouseDoubleClickEvent ().

[virtual protected] void QTextEdit:: mouseMoveEvent ( QMouseEvent * e )

重实现自 QWidget::mouseMoveEvent ().

[virtual protected] void QTextEdit:: mousePressEvent ( QMouseEvent * e )

重实现自 QWidget::mousePressEvent ().

[virtual protected] void QTextEdit:: mouseReleaseEvent ( QMouseEvent * e )

重实现自 QWidget::mouseReleaseEvent ().

void QTextEdit:: moveCursor ( QTextCursor::MoveOperation operation , QTextCursor::MoveMode mode = QTextCursor::MoveAnchor)

移动光标通过履行给定 operation .

mode is QTextCursor::KeepAnchor ,光标选择由它移动覆盖的文本。这与用户达成的效果相同,当按下 Shift 键和采用光标键移动光标时。

该函数在 Qt 4.2 引入。

另请参阅 QTextCursor::movePosition ().

[virtual protected] void QTextEdit:: paintEvent ( QPaintEvent * event )

重实现自 QWidget::paintEvent ().

可以在子类中重实现此事件处理程序以接收传入的描绘事件 event 。通常不必重实现此函数在子类 QTextEdit .

警告: 底层文本文档必须不被修改从此函数的重实现中。

[slot] void QTextEdit:: paste ()

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

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

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

另请参阅 cut () 和 copy ().

void QTextEdit:: print ( QPagedPaintDevice * printer ) const

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

该函数在 Qt 4.3 引入。

另请参阅 QTextDocument::print ().

[slot] void QTextEdit:: redo ()

重做上一操作。

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

该函数在 Qt 4.2 引入。

另请参阅 undo ().

[signal] void QTextEdit:: redoAvailable ( bool available )

This signal is emitted whenever redo operations become available ( available is true) or unavailable ( available is false).

[virtual protected] void QTextEdit:: resizeEvent ( QResizeEvent * e )

重实现自 QWidget::resizeEvent ().

[virtual protected] void QTextEdit:: scrollContentsBy ( int dx , int dy )

重实现自 QAbstractScrollArea::scrollContentsBy ().

[slot] void QTextEdit:: scrollToAnchor (const QString & name )

卷动文本编辑,以便锚点采用给定 name is visible; does nothing if the name is empty, or is already visible, or isn't found.

[slot] void QTextEdit:: selectAll ()

选择所有文本。

另请参阅 copy (), cut (),和 textCursor ().

[signal] void QTextEdit:: selectionChanged ()

此信号被发射每当选定改变时。

另请参阅 copyAvailable ().

[slot] void QTextEdit:: setAlignment ( Qt::Alignment a )

把当前段落的对齐方式设为 a 。有效对齐方式是 Qt::AlignLeft , Qt::AlignRight , Qt::AlignJustify and Qt::AlignCenter (水平居中)。

另请参阅 alignment ().

void QTextEdit:: setCurrentCharFormat (const QTextCharFormat & format )

把新文本插入时使用的字符格式设为 format 通过调用 QTextCursor::setCharFormat () 在编辑器的光标。若编辑器拥有选定,把字符格式直接应用到选定。

另请参阅 currentCharFormat ().

[slot] void QTextEdit:: setCurrentFont (const QFont & f )

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

另请参阅 currentFont (), setFontPointSize (),和 setFontFamily ().

void QTextEdit:: setExtraSelections (const QList < ExtraSelection > & selections )

此函数允许采用给定颜色临时标记某些文档区域,指定通过 selections 。例如:这在编程编辑器中可以是有用的,采用给定背景颜色标记整行文本以指示断点的存在。

该函数在 Qt 4.2 引入。

另请参阅 QTextEdit::ExtraSelection and extraSelections ().

[slot] void QTextEdit:: setFontFamily (const QString & fontFamily )

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

另请参阅 fontFamily () 和 setCurrentFont ().

[slot] void QTextEdit:: setFontItalic ( bool italic )

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

另请参阅 fontItalic ().

[slot] void QTextEdit:: setFontPointSize ( qreal s )

将当前格式的点大小设为 s .

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

另请参阅 fontPointSize (), setCurrentFont (),和 setFontFamily ().

[slot] void QTextEdit:: setFontUnderline ( bool underline )

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

另请参阅 fontUnderline ().

[slot] void QTextEdit:: setFontWeight ( int weight )

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 枚举。

另请参阅 fontWeight (), setCurrentFont (),和 setFontFamily ().

[slot] void QTextEdit:: setPlainText (const QString & text )

把文本编辑的文本更改为字符串 text 。移除任何以前文本。

text 被解释为纯文本。

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

注意: Setter 函数对于特性 plainText .

另请参阅 toPlainText ().

[slot] void QTextEdit:: setText (const QString & text )

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

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

该函数在 Qt 4.2 引入。

另请参阅 toPlainText () 和 toHtml ().

[slot] void QTextEdit:: setTextBackgroundColor (const QColor & c )

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

该函数在 Qt 4.4 引入。

另请参阅 textBackgroundColor ().

[slot] void QTextEdit:: setTextColor (const QColor & c )

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

另请参阅 textColor ().

void QTextEdit:: setTextCursor (const QTextCursor & cursor )

设置可见 cursor .

另请参阅 textCursor ().

[virtual protected] void QTextEdit:: showEvent ( QShowEvent * )

重实现自 QWidget::showEvent ().

QColor QTextEdit:: textBackgroundColor () const

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

该函数在 Qt 4.4 引入。

另请参阅 setTextBackgroundColor ().

[signal] void QTextEdit:: textChanged ()

This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.

注意: 通知程序信号对于特性 html .

QColor QTextEdit:: textColor () const

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

另请参阅 setTextColor ().

QTextCursor QTextEdit:: textCursor () const

返回副本为 QTextCursor 表示当前可见光标。注意:改变返回光标不影响 QTextEdit 的光标; 使用 setTextCursor () 以更新可见光标。

另请参阅 setTextCursor ().

QString QTextEdit:: toPlainText () const

QString QTextEdit::toPlainText() const

把文本编辑的文本作为纯文本返回。

注意: Getter 函数对于特性 plainText .

另请参阅 QTextEdit::setPlainText ().

[slot] void QTextEdit:: undo ()

撤消上一操作。

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

该函数在 Qt 4.2 引入。

另请参阅 redo ().

[signal] void QTextEdit:: undoAvailable ( bool available )

This signal is emitted whenever undo operations become available ( available is true) or unavailable ( available is false).

[virtual protected] void QTextEdit:: wheelEvent ( QWheelEvent * e )

重实现自 QWidget::wheelEvent ().

[slot] void QTextEdit:: zoomIn ( int range = 1)

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.

另请参阅 zoomOut ().

[slot] void QTextEdit:: zoomOut ( int range = 1)

这是重载函数。

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.

另请参阅 zoomIn ().