QPlainTextEdit 类

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

头: #include <QPlainTextEdit>
qmake: QT += widgets
Since: Qt 4.4
继承: QAbstractScrollArea

公共类型

enum LineWrapMode { NoWrap, WidgetWidth }

特性

公共函数

QPlainTextEdit (QWidget * parent = Q_NULLPTR)
QPlainTextEdit (const QString & text , QWidget * parent = Q_NULLPTR)
virtual ~QPlainTextEdit ()
QString anchorAt (const QPoint & pos ) const
bool backgroundVisible () const
int blockCount () const
bool canPaste () const
bool centerOnScroll () const
QMenu * createStandardContextMenu ()
QMenu * createStandardContextMenu (const QPoint & position )
QTextCharFormat currentCharFormat () 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<QTextEdit::ExtraSelection> extraSelections () const
bool find (const QString & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())
bool find (const QRegExp & exp , QTextDocument::FindFlags options = QTextDocument::FindFlags())
bool isReadOnly () const
bool isUndoRedoEnabled () const
LineWrapMode lineWrapMode () const
virtual QVariant loadResource (int type , const QUrl & name )
int maximumBlockCount () const
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 setBackgroundVisible (bool visible )
void setCenterOnScroll (bool enabled )
void setCurrentCharFormat (const QTextCharFormat & format )
void setCursorWidth (int width )
void setDocument (QTextDocument * document )
void setDocumentTitle (const QString & title )
void setExtraSelections (const QList<QTextEdit::ExtraSelection> & selections )
void setLineWrapMode (LineWrapMode mode )
void setMaximumBlockCount (int maximum )
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
QTextCursor textCursor () const
Qt::TextInteractionFlags textInteractionFlags () const
QString toPlainText () const
QTextOption::WrapMode wordWrapMode () const

重实现公共函数

virtual QVariant inputMethodQuery (Qt::InputMethodQuery property ) const

公共槽

void appendHtml (const QString & html )
void appendPlainText (const QString & text )
void centerCursor ()
void clear ()
void copy ()
void cut ()
void insertPlainText (const QString & text )
void paste ()
void redo ()
void selectAll ()
void setPlainText (const QString & text )
void undo ()
void zoomIn (int range = 1)
void zoomOut (int range = 1)

信号

void blockCountChanged (int newBlockCount )
void copyAvailable (bool yes )
void cursorPositionChanged ()
void modificationChanged (bool changed )
void redoAvailable (bool available )
void selectionChanged ()
void textChanged ()
void undoAvailable (bool available )
void updateRequest (const QRect & rect , int dy )

保护函数

QRectF blockBoundingGeometry (const QTextBlock & block ) const
QRectF blockBoundingRect (const QTextBlock & block ) const
virtual bool canInsertFromMimeData (const QMimeData * source ) const
QPointF contentOffset () const
virtual QMimeData * createMimeDataFromSelection () const
QTextBlock firstVisibleBlock () const
QAbstractTextDocumentLayout::PaintContext getPaintContext () 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 * e )
virtual void resizeEvent (QResizeEvent * e )
virtual void scrollContentsBy (int dx , int dy )
virtual void showEvent ( QShowEvent * )
virtual void wheelEvent (QWheelEvent * e )

额外继承成员

详细描述

QPlainTextEdit class provides a widget that is used to edit and display plain text.

介绍和概念

QPlainTextEdit is an advanced viewer/editor supporting plain text. It is optimized to handle large documents and to respond quickly to user input.

QPlainText 使用了一样的技术和概念,如 QTextEdit ,但为纯文本处理进行了优化。

QPlainTextEdit 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. Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color.

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

使用 QPlainTextEdit 作为显示 Widget

设置或替代文本使用 setPlainText () 删除并替换现有文本,把文本传递给 setPlainText ().

插入文本可用使用 QTextCursor 类或使用方便函数 insertPlainText (), appendPlainText () 或 paste ().

默认情况下,文本编辑在空白处自动换行以拟合在文本编辑 Widget 内。 setLineWrapMode () 函数用于指定想要的换行种类, WidgetWidth or NoWrap 若不想要任何换行。若使用自动换行到 Widget 的宽度 WidgetWidth ,可以指定是在空白处断开还是在任何地方断开采用 setWordWrapMode ().

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

If you want to limit the total number of paragraphs in a QPlainTextEdit , as it is for example useful in a log viewer, then you can use the maximumBlockCount 特性。组合 setMaximumBlockCount () 和 appendPlainText () turns QPlainTextEdit into an efficient viewer for log text. The scrolling can be reduced with the centerOnScroll () 特性,使日志查看器甚至更快。文本可以按有限方式被格式化,使用语法高亮 (见下文),或追加 html 格式文本采用 appendHtml (). While QPlainTextEdit does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer.

只读键绑定

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

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

使用 QPlainTextEdit 作为编辑器

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

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

QPlainTextEdit holds a QTextDocument 对象,可以被检索使用 document () 方法。还可以设置自己的文档对象使用 setDocument (). QTextDocument 发射 textChanged () 信号若文本改变,且它还提供 isModified() 函数,返回 true 若文本在加载或采用 false 作为自变量最后调用 setModified 后被修改。此外,它提供撤消和重做方法。

句法高亮

就像 QTextEdit , QPlainTextEdit works together with QSyntaxHighlighter .

编辑键绑定

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

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

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

和 QTextEdit 的差异

QPlainTextEdit is a thin class, implemented by using most of the technology that is behind QTextEdit and QTextDocument 。其性能优于 QTextEdit stem mostly from using a different and simplified text layout called QPlainTextDocumentLayout on the text document (see QTextDocument::setDocumentLayout ()). The plain text document layout does not support tables nor embedded frames, and replaces a pixel-exact height calculation with a line-by-line respectively paragraph-by-paragraph scrolling approach . This makes it possible to handle significantly larger documents, and still resize the editor with line wrap enabled in real time. It also makes for a fast log viewer (see setMaximumBlockCount ()).

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

成员类型文档编制

enum QPlainTextEdit:: LineWrapMode

常量
QPlainTextEdit::NoWrap 0
QPlainTextEdit::WidgetWidth 1

特性文档编制

backgroundVisible : bool

This property holds whether the palette background is visible outside the document area

If set to true, the plain text edit paints the palette background on the viewport area not covered by the text document. Otherwise, if set to false, it won't. The feature makes it possible for the user to visually distinguish between the area of the document, painted with the base color of the palette, and the empty area not covered by any document.

默认为 false。

访问函数:

bool backgroundVisible () const
void setBackgroundVisible (bool visible )

blockCount : const int

此特性保持文档文本块数。

默认情况下,此特性在空文档中包含 1 值。

访问函数:

int blockCount () const

centerOnScroll : bool

此特性保持光标是否应该居中屏幕

If set to true, the plain text edit scrolls the document vertically to make the cursor visible at the center of the viewport. This also allows the text edit to scroll below the end of the document. Otherwise, if set to false, the plain text edit scrolls the smallest amount possible to ensure the cursor is visible. The same algorithm is applied to any new line appended through appendPlainText ().

默认为 false。

访问函数:

bool centerOnScroll () const
void setCenterOnScroll (bool enabled )

另请参阅 centerCursor () 和 ensureCursorVisible ().

cursorWidth : int

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

访问函数:

int cursorWidth () const
void setCursorWidth (int width )

documentTitle : QString

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

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

访问函数:

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

lineWrapMode : LineWrapMode

此特性保持换行模式

默认模式为 WidgetWidth 促使单词在文本编辑右边缘换行。换行发生在空白处,保持整个单词完整。若想要换行发生在单词内,使用 setWordWrapMode ().

访问函数:

LineWrapMode lineWrapMode () const
void setLineWrapMode (LineWrapMode mode )

maximumBlockCount : int

此特性保持用于文档块的限制。

指定文档可能拥有的最大块数。若采用此特性的指定文档有更多块,则块被移除从文档开头。

文档的负值 (或零值) 指定可能包含无限数量的块。

默认值为 0。

注意:设置此特性会把限制立即应用于文档内容。设置此特性还会禁用撤消重做历史。

访问函数:

int maximumBlockCount () const
void setMaximumBlockCount (int maximum )

overwriteMode : bool

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

As with many text editors, the plain 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 (新文本不覆写现有文本)。

访问函数:

bool overwriteMode () const
void setOverwriteMode (bool overwrite )

placeholderText : QString

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

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

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

该特性在 Qt 5.3 引入。

访问函数:

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

另请参阅 document ().

plainText : QString

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

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

访问函数:

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

通知程序信号:

void textChanged ()

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 的值。

访问函数:

int tabStopWidth () const
void setTabStopWidth (int width )

textInteractionFlags : Qt::TextInteractionFlags

指定标签应如何与用户输入交互,若它显示文本。

若标志包含 Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard 那么聚焦策略还被自动设为 Qt::ClickFocus .

默认值取决于 QPlainTextEdit 是只读或可编辑。

访问函数:

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

默认情况下此特性为 true .

访问函数:

bool isUndoRedoEnabled () const
void setUndoRedoEnabled (bool enable )

wordWrapMode : QTextOption::WrapMode

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

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

访问函数:

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

另请参阅 QTextOption::WrapMode .

成员函数文档编制

QPlainTextEdit:: QPlainTextEdit ( QWidget * parent = Q_NULLPTR)

构造空的 QPlainTextEdit 采用父级 parent .

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

构造 QPlainTextEdit 采用父级 parent 。文本编辑将显示纯文本 text .

[virtual] QPlainTextEdit:: ~QPlainTextEdit ()

析构函数。

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

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

该函数在 Qt 4.7 引入。

[slot] void QPlainTextEdit:: appendHtml (const QString & html )

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

appendPlainText ()

[slot] void QPlainTextEdit:: appendPlainText (const QString & text )

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

另请参阅 appendHtml ().

[protected] QRectF QPlainTextEdit:: blockBoundingGeometry (const QTextBlock & block ) const

Returns the bounding rectangle of the text block in content coordinates. Translate the rectangle with the contentOffset () to get visual coordinates on the viewport.

另请参阅 firstVisibleBlock () 和 blockBoundingRect ().

[protected] QRectF QPlainTextEdit:: blockBoundingRect (const QTextBlock & block ) const

Returns the bounding rectangle of the text block in the block's own coordinates.

另请参阅 blockBoundingGeometry ().

[signal] void QPlainTextEdit:: blockCountChanged ( int newBlockCount )

此信号被发射每当块计数改变时。新的块计数被传入 newBlockCount .

[virtual protected] bool QPlainTextEdit:: 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.

bool QPlainTextEdit:: canPaste () const

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

[slot] void QPlainTextEdit:: centerCursor ()

卷动文档以使光标垂直居中。

另请参阅 ensureCursorVisible () 和 centerOnScroll .

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

重实现自 QWidget::changeEvent ().

[slot] void QPlainTextEdit:: clear ()

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

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

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

[protected] QPointF QPlainTextEdit:: contentOffset () const

返回视口坐标中的内容原点。

The origin of the content of a plain text edit is always the top left corner of the first visible text block. The content offset is different from (0,0) when the text has been scrolled horizontally, or when the first visible block has been scrolled partially off the screen, i.e. the visible text does not start with the first line of the first visible block, or when the first visible block is the very first block and the editor displays a margin.

另请参阅 firstVisibleBlock (), horizontalScrollBar (),和 verticalScrollBar ().

[virtual protected] void QPlainTextEdit:: 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 MyQPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = createStandardContextMenu();
    menu->addAction(tr("My Menu Item"));
    //...
    menu->exec(event->globalPos());
    delete menu;
}
					

[slot] void QPlainTextEdit:: copy ()

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

另请参阅 copyAvailable ().

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

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

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

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

另请参阅 selectionChanged ().

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

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

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

QMenu *QPlainTextEdit:: createStandardContextMenu ()

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

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

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

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

该函数在 Qt 5.5 引入。

QTextCharFormat QPlainTextEdit:: currentCharFormat () const

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

另请参阅 setCurrentCharFormat ().

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

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

[signal] void QPlainTextEdit:: cursorPositionChanged ()

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

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

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

QRect QPlainTextEdit:: cursorRect () const

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

[slot] void QPlainTextEdit:: cut ()

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

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

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

QTextDocument *QPlainTextEdit:: document () const

返回底层文档指针。

另请参阅 setDocument ().

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

重实现自 QWidget::dragEnterEvent ().

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

重实现自 QWidget::dragLeaveEvent ().

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

重实现自 QWidget::dragMoveEvent ().

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

重实现自 QWidget::dropEvent ().

void QPlainTextEdit:: ensureCursorVisible ()

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

另请参阅 centerCursor () 和 centerOnScroll .

QList < QTextEdit::ExtraSelection > QPlainTextEdit:: extraSelections () const

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

另请参阅 setExtraSelections ().

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

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

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

这是重载函数。

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

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

该函数在 Qt 5.3 引入。

[protected] QTextBlock QPlainTextEdit:: firstVisibleBlock () const

Returns the first visible block.

另请参阅 blockBoundingRect ().

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

重实现自 QWidget::focusInEvent ().

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

重实现自 QWidget::focusNextPrevChild ().

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

重实现自 QWidget::focusOutEvent ().

[protected] QAbstractTextDocumentLayout::PaintContext QPlainTextEdit:: getPaintContext () const

Returns the paint context for the viewport (), useful only when reimplementing paintEvent ().

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

重实现自 QWidget::inputMethodEvent ().

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

重实现自 QWidget::inputMethodQuery ().

[virtual protected] void QPlainTextEdit:: 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.

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

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

它相当于

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

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

重实现自 QWidget::keyPressEvent ().

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

重实现自 QWidget::keyReleaseEvent ().

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

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

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

另请参阅 QTextDocument::loadResource ().

void QPlainTextEdit:: 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 ().

[signal] void QPlainTextEdit:: modificationChanged ( bool changed )

此信号被发射每当文档的内容以影响修改状态的方式更改时。若 changed 为 true,文档已被修改;否则它为 false。

例如:调用文档 setModified(false),然后插入文本导致发射信号。若撤消该操作,导致文档返回其原始未修改状态,将再次发射信号。

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

重实现自 QWidget::mouseDoubleClickEvent ().

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

重实现自 QWidget::mouseMoveEvent ().

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

重实现自 QWidget::mousePressEvent ().

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

重实现自 QWidget::mouseReleaseEvent ().

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

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

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

另请参阅 QTextCursor::movePosition ().

[virtual protected] void QPlainTextEdit:: paintEvent ( QPaintEvent * e )

重实现自 QWidget::paintEvent ().

[slot] void QPlainTextEdit:: paste ()

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

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

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

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

void QPlainTextEdit:: 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.

另请参阅 QTextDocument::print ().

[slot] void QPlainTextEdit:: redo ()

重做上一操作。

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

另请参阅 undo ().

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

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

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

重实现自 QWidget::resizeEvent ().

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

重实现自 QAbstractScrollArea::scrollContentsBy ().

[slot] void QPlainTextEdit:: selectAll ()

选择所有文本。

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

[signal] void QPlainTextEdit:: selectionChanged ()

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

另请参阅 copyAvailable ().

void QPlainTextEdit:: setCurrentCharFormat (const QTextCharFormat & format )

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

另请参阅 currentCharFormat ().

void QPlainTextEdit:: setDocument ( QTextDocument * document )

使其成为文本编辑器的新文档,对于 document .

父级 QObject 文档的提供者仍然是对象的所有者。若当前文档是文本编辑器的子级,则将其删除。

文档必须具有文档布局,继承 QPlainTextDocumentLayout (见 QTextDocument::setDocumentLayout ()).

另请参阅 document ().

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

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

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

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

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

text 被解释为纯文本。

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

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

另请参阅 toPlainText ().

void QPlainTextEdit:: setTextCursor (const QTextCursor & cursor )

设置可见 cursor .

另请参阅 textCursor ().

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

重实现自 QWidget::showEvent ().

[signal] void QPlainTextEdit:: textChanged ()

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

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

QTextCursor QPlainTextEdit:: textCursor () const

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

另请参阅 setTextCursor ().

QString QPlainTextEdit:: toPlainText () const

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

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

另请参阅 QPlainTextEdit::setPlainText ().

[slot] void QPlainTextEdit:: undo ()

撤消上一操作。

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

另请参阅 redo ().

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

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

[signal] void QPlainTextEdit:: updateRequest (const QRect & rect , int dy )

此信号被发射当文本文档需要更新指定 rect 。若文本被卷动, rect 将覆盖整个视口区域。若文本被垂直卷动, dy 携带视口被卷动的像素数量。

信号的目的是在纯文本编辑子类中支持额外 Widget,如:展示行号、断点或其它额外信息。

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

重实现自 QWidget::wheelEvent ().

[slot] void QPlainTextEdit:: 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 QPlainTextEdit:: 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 ().