QTextLength Class

QTextLength 类封装了QTextDocument 中使用的不同长度类型 ... 更多...

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

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

公共类型

enum Type { VariableLength, FixedLength, PercentageLength }

公共函数

QTextLength()
QTextLength(QTextLength::Type type, qreal value)
qreal rawValue() const
QTextLength::Type type() const
qreal value(qreal maximumLength) const
QVariant operator QVariant() const
bool operator!=(const QTextLength &other) const
bool operator==(const QTextLength &other) const

详细说明

当我们为文本文档中的元素指定长度值时,往往需要提供一些其他信息,以便按照我们期望的方式使用该长度。例如,当我们指定表格宽度时,该值可以是一个固定的像素数,也可以是一个百分比值。这些信息会改变值的含义和使用方式。

一般来说,该类用于指定表格宽度。这些宽度可以指定为固定的像素数、占包含框架宽度的百分比,也可以指定为可变宽度,使其只占用所需的空间。

另请参阅 QTextTable

成员类型文档

enum QTextLength::Type

该枚举描述了长度对象的不同类型。

常量描述
QTextLength::VariableLength0对象的宽度是可变的
QTextLength::FixedLength1对象的宽度是固定的
QTextLength::PercentageLength2对象宽度是最大宽度的百分比

另请参阅 type().

成员函数文档

QTextLength::QTextLength()

构造一个新的 length 对象,该对象代表一个可变大小。

[explicit] QTextLength::QTextLength(QTextLength::Type type, qreal value)

以给定的typevalue 构建一个新的 length 对象。

qreal QTextLength::rawValue() const

返回特定于长度类型的约束值。如果长度为QTextLength::PercentageLength ,则原始值为百分比,范围为 0 至 100。如果长度为QTextLength::FixedLength ,则返回固定值。对于可变长度,则返回 0。

QTextLength::Type QTextLength::type() const

返回此长度对象的类型。

另请参见 QTextLength::Type

qreal QTextLength::value(qreal maximumLength) const

根据 length 对象的类型和指定的maximumLength ,返回有效长度。

另请参见 type().

QVariant QTextLength::operator QVariant() const

QVariant

bool QTextLength::operator!=(const QTextLength &other) const

如果该文本长度与other 文本长度不同,则返回true

bool QTextLength::operator==(const QTextLength &other) const

如果此文本长度与other 文本长度相同,则返回true

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