QFont::Tag Struct
struct QFont::TagQFont::Tag 类型可用于访问高级字体功能。更多内容...
该结构体在 Qt 6.7 中引入。
公共函数
| Tag() | |
| Tag(const char (&str)[N]) | |
| bool | isValid() const |
| QByteArray | toString() const |
| quint32 | value() const |
静态公共成员
| std::optional<QFont::Tag> | fromString(QAnyStringView view) |
| std::optional<QFont::Tag> | fromValue(quint32 value) |
相关的非成员
| Qt::strong_ordering | compareThreeWay(const QFont::Tag &lhs, const QFont::Tag &rhs) |
| bool | comparesEqual(const QFont::Tag &lhs, const QFont::Tag &rhs) |
| size_t | qHash(QFont::Tag key, size_t seed = 0) |
| QDataStream & | operator<<(QDataStream &, QFont::Tag) |
| QDataStream & | operator>>(QDataStream &, QFont::Tag &) |
详细说明
QFont 在塑造文本时提供对高级功能的访问。一个功能由一个标签定义,该标签可以表示为一个四字符字符串,或一个 32 位整数值。 该类型以类型安全的方式表示此类标签。它可以通过四字符的 8 位字符串字面量,或相应的 32 位整数值来构造。使用长度不符的字符串字面量将导致编译时错误。
QFont font;
// Correct
font.setFeature("frac");
// Wrong - won't compile
font.setFeature("fraction");
// Wrong - will produce runtime warning and fail
font.setFeature(u"fraction"_s);命名构造函数允许通过 32 位整数或字符串值创建标签,若输入无效,则返回std::nullopt 。
另请参阅 QFont::setFeature() 和QFont::featureTags()。
成员函数文档
[constexpr noexcept default] Tag::Tag()
默认构造函数,会生成一个无效的标签。
[constexpr noexcept] template <size_t N> Tag::Tag(const char (&str)[N])
根据字符串字面量str 构建一个标签。该字面量必须恰好由四个字符组成。
font.setFeature("frac", 1);另请参阅 fromString() 和fromValue()。
[static noexcept] std::optional<QFont::Tag> Tag::fromString(QAnyStringView view)
返回一个由view 中的字符串构建的标签。该字符串的长度必须恰好为四个字符。
如果输入字符串长度不是四个字符,或者生成的标签无效,则返回std::nullopt 。
[static constexpr noexcept] std::optional<QFont::Tag> Tag::fromValue(quint32 value)
返回一个由value 构建的标签,如果生成的标签无效,则返回std::nullopt 。
另请参阅 isValid()。
[constexpr noexcept] bool Tag::isValid() const
返回该标签是否有效。如果标签的值不为零,则该标签有效。
另请参阅 value()、fromValue() 以及fromString()。
QByteArray Tag::toString() const
返回该标签的字符串表示形式,以字节数组的形式呈现。
另请参阅 fromString()。
[constexpr noexcept] quint32 Tag::value() const
返回此标签的数值。
相关的非成员
[constexpr noexcept] Qt::strong_ordering compareThreeWay(const QFont::Tag &lhs, const QFont::Tag &rhs)
[constexpr noexcept] bool comparesEqual(const QFont::Tag &lhs, const QFont::Tag &rhs)
比较lhs 和rhs ,以确认两者是否相等及排序是否一致。
[constexpr noexcept] size_t qHash(QFont::Tag key, size_t seed = 0)
返回key 的哈希值,并使用seed 作为计算的种子。
QDataStream &operator<<(QDataStream &, QFont::Tag)
QDataStream &operator>>(QDataStream &, QFont::Tag &)
QFont::Tag 的数据流运算符。
© 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.