QTextListFormat Class

QTextListFormat 类为QTextDocument 中的列表提供格式化信息

头文件: #include <QTextListFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QTextFormat

注意:该类中的所有函数都是可重入的

公共类型

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

另请参阅 style() 和Style

[since 6.6] int QTextListFormat::start() const

如果style() 是QTextListFormat::ListDecimal ,则返回第一个列表项要显示的数字,或用于抵消其他排序列表类型。

此函数在 Qt 6.6 中引入。

另请参阅 setStart()。

QTextListFormat::Style QTextListFormat::style() const

返回列表格式的样式。

另请参阅 setStyle() 和Style

© 2025 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.