QTextListFormat Class
QTextListFormat 类为QTextDocument 中的列表提供了格式设置信息。更多内容...
| 头文件: | #include <QTextListFormat> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 继承自: | QTextFormat |
- 所有成员列表(包括继承的成员)
- QTextListFormat 属于“富文本处理 API”和“隐式共享类”的一部分。
注意:该类中的所有函数均为可重入的。
公共类型
| enum | Style { ListDisc, ListCircle, ListSquare, ListDecimal, ListLowerAlpha, …, ListUpperRoman } |
公共函数
| QTextListFormat() | |
| int | indent() const |
| bool | isValid() const |
| QString | numberPrefix() const |
| QString | numberSuffix() const |
| void | setIndent(int indentation) |
| void | setNumberPrefix(const QString &numberPrefix) |
| void | setNumberSuffix(const QString &numberSuffix) |
(since 6.6) void | setStart(int start) |
| void | setStyle(QTextListFormat::Style style) |
(since 6.6) int | start() const |
| QTextListFormat::Style | style() const |
详细说明
列表由一个或多个项目组成,这些项目以文本块的形式表示。列表的格式指定了列表中项目的显示方式。具体而言,它决定了每个项目的缩进和样式。
项目的缩进是一个整数值,它使每个项目从左边距偏移一定距离。该值可通过indent()读取,并通过setIndent()设置。
用于装饰每个项目的样式通过setStyle()设置,并可通过style()函数读取。该样式控制列表项目中使用的项目符号类型和编号方案。请注意,使用十进制编号方案的列表从1开始计数,而不是从0开始,除非通过setStart()进行了覆盖。
可以设置样式属性来进一步配置列表项的外观;例如,可以使用 ListNumberPrefix 和 ListNumberSuffix 属性自定义有序列表中使用的数字,使其显示为 (1)、(2)、(3) 等:
QTextListFormat listFormat;
listFormat.setStyle(QTextListFormat::ListDecimal);
listFormat.setNumberPrefix("(");
listFormat.setNumberSuffix(")");
cursor.insertList(listFormat);另请参阅 QTextList 。
成员类型文档
enum QTextListFormat::Style
此枚举描述了用于装饰列表项的符号:
| 常量 | 值 | 描述 |
|---|---|---|
QTextListFormat::ListDisc | -1 | 实心圆 |
QTextListFormat::ListCircle | -2 | 空心圆 |
QTextListFormat::ListSquare | -3 | 实心正方形 |
QTextListFormat::ListDecimal | -4 | 按升序排列的小数值 |
QTextListFormat::ListLowerAlpha | -5 | 按字母顺序排列的小写拉丁字母 |
QTextListFormat::ListUpperAlpha | -6 | 按字母顺序排列的大写拉丁字母 |
QTextListFormat::ListLowerRoman | -7 | 小写罗马数字(仅支持最多 4999 个项目) |
QTextListFormat::ListUpperRoman | -8 | 大写罗马数字(仅支持最多 4999 个项目) |
成员函数文档
QTextListFormat::QTextListFormat()
创建一个新的列表格式对象。
int QTextListFormat::indent() const
返回列表格式的缩进量。将该缩进量乘以QTextDocument::indentWidth 属性,即可得到以像素为单位的实际缩进量。
另请参阅 setIndent()。
bool QTextListFormat::isValid() const
如果此列表格式有效,则返回true ;否则返回false 。
QString QTextListFormat::numberPrefix() const
返回列表格式的数字前缀。
另请参阅 setNumberPrefix()。
QString QTextListFormat::numberSuffix() const
返回列表格式的数字后缀。
另请参阅 setNumberSuffix()。
void QTextListFormat::setIndent(int indentation)
设置列表格式的“indentation ”。将缩进值乘以“QTextDocument::indentWidth ”属性,即可得到以像素为单位的有效缩进值。
另请参阅 indent()。
void QTextListFormat::setNumberPrefix(const QString &numberPrefix)
将列表格式的数字前缀设置为由numberPrefix 指定的字符串。此功能可用于所有已排序的列表类型,对未排序的列表类型则无任何影响。
默认前缀为空字符串。
另请参阅 numberPrefix()。
void QTextListFormat::setNumberSuffix(const QString &numberSuffix)
将列表格式的数字后缀设置为由numberSuffix 指定的字符串。此功能可用于所有已排序的列表类型,对未排序的列表类型则无影响。
默认后缀为“.”。
另请参阅 numberSuffix()。
[since 6.6] void QTextListFormat::setStart(int start)
设置列表格式的start 索引。
这允许您将列表的起始索引设为非1。此功能适用于所有已排序的列表类型:例如,若style()的值为QTextListFormat::ListLowerAlpha ,且start()的值为4 ,则列表的第一个项目将以“d”开头。此设置对未排序的列表类型没有任何影响。
默认起始值为1 。
该函数在 Qt 6.6 中引入。
另请参阅 start()。
void QTextListFormat::setStyle(QTextListFormat::Style style)
设置列表格式的style 。
[since 6.6] int QTextListFormat::start() const
返回应显示在第一个列表项中的数字;若style()的值为QTextListFormat::ListDecimal ,则返回该数字;否则,用于偏移其他已排序的列表类型。
该函数于 Qt 6.6 中引入。
另请参阅 setStart()。
QTextListFormat::Style QTextListFormat::style() const
返回列表格式的样式。
© 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.