本页内容

富文本处理

Qt提供了一组用于创建、编辑和渲染结构化富文本文档的类。这些类以QTextDocument 为核心,该类表示具有明确内部结构的富文本文档。通过直接操作QTextDocument ,应用程序可以创建、修改和检查富文本,而无需依赖中间标记格式。

您可以通过两个互补的接口访问文档信息:

接口描述
基于光标的接口(QTextCursor )支持模拟文本编辑器中用户操作的编辑操作。编辑操作可保持底层文档的结构完整性。
只读层次结构界面提供文档的高级结构视图。该界面适用于搜索、检查和导出内容等任务。

富文本序列化

QTextDocument 支持与以下标记格式的相互序列化:

富文本主题

富文本处理 API

Qt 提供了一套用于解析、渲染、处理和编辑富文本的广泛类集合。

QAbstractTextDocumentLayout

用于为 QTextDocument 实现自定义布局的抽象基类

QFont

指定用于绘制文本的字体的查询

QPlainTextDocumentLayout

为 QTextDocument 实现纯文本布局

QPlainTextEdit

用于编辑和显示纯文本的小部件

QSyntaxHighlighter

允许您定义语法高亮规则,此外,您还可以使用该类查询文档的当前格式或用户数据

QTextBlock

用于存放 QTextDocument 中文本片段的容器

QTextBlock::iterator

QTextBlock::iterator 类提供了一个用于读取 QTextBlock 内容的迭代器

QTextBlockFormat

QTextDocument 中文本块的格式信息

QTextBlockGroup

用于存放 QTextDocument 内文本块的容器

QTextBlockUserData

用于将自定义数据与文本块关联

QTextBrowser

带超文本导航功能的富文本浏览器

QTextCharFormat

QTextDocument 中字符的格式信息

QTextCursor

提供用于访问和修改 QTextDocument 的 API

QTextDocument

用于存储格式化后的文本

QTextDocumentFragment

表示来自 QTextDocument 的一个格式化文本片段

QTextDocumentWriter

用于将 QTextDocument 写入文件或其他设备的与格式无关的接口

QTextEdit

用于编辑和显示纯文本及富文本的小部件

QTextFormat

QTextDocument 的格式化信息

QTextFragment

在 QTextDocument 中保存一段带有单个 QTextCharFormat 的文本

QTextFrame

表示 QTextDocument 中的一个框架

QTextFrame::iterator

用于读取 QTextFrame 内容的迭代器

QTextFrameFormat

QTextDocument 中框架的格式信息

QTextImageFormat

QTextDocument 中图像的格式信息

QTextInlineObject

表示 QAbstractTextDocumentLayout 及其实现中的内联对象

QTextLayout

用于文本的排版和渲染

QTextLength

封装了 QTextDocument 中使用的不同类型长度

QTextLine

表示 QTextLayout 中的文本行

QTextList

QTextDocument 中经过格式化的项目列表

QTextListFormat

QTextDocument 中列表的格式化信息

QTextObject

可将 QTextDocument 中的部分内容分组在一起的各类对象的基类

QTextOption

关于一般富文本属性的描述

QTextTable

表示 QTextDocument 中的表格

QTextTableCell

表示 QTextTable 中单元格的属性

QTextTableCellFormat

QTextDocument 中表格单元格的格式设置信息

QTextTableFormat

QTextDocument 中表格的格式设置信息

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.