QTextListFormat 类
QTextListFormat 类提供对 QTextDocument 中列表的格式信息。 更多...
| 头文件 | #include <QTextListFormat> | 
| CMake | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) | 
| qmake | QT += gui | 
| 继承 | QTextFormat | 
- 所有成员的列表,包括继承的成员
- QTextListFormat 是富文本处理 API 和隐式共享类的组成部分 Rich Text Processing APIs 和 Implicitly Shared Classes。
注意: 此类中的所有函数都是 重入的。
公共类型
| 枚举 | 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。
成员类型文档
枚举 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)
设置列表格式的缩进。缩进乘以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
返回列表格式的样式。
© 2024 Qt 公司 Ltd。本说明中包含的贡献是各自所有者的版权。本文档是根据自由软件基金会发布的 GNU 自由文档许可协议版本 1.3 许可的。Qt 以及相应的标志是芬兰的 Qt 公司及其在全世界范围的其他国家的商标。所有其他商标均为各自所有者的财产。