- Qt 6.8
- Qt GUI
- C++ Classes
- Tag
- Qt 6.8.3 Reference Documentation

# Tag Struct

struct QFont::Tag

The QFont::Tag type provides access to advanced font features. More...

This struct was introduced in Qt 6.7.

- List of all members, including inherited members

## Public Functions

| Tag()
| Tag(const char (&)[N] str)
bool | isValid() const
QByteArray | toString() const
quint32 | value() const

## Static Public Members

std::optional<QFont::Tag> | fromString(QAnyStringView view)
std::optional<QFont::Tag> | fromValue(quint32 value)

## Related Non-Members

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)

## Detailed Description

QFont provides access to advanced features when shaping text. A feature is defined by a tag, which can be represented as a four-character string, or as a 32bit integer value. This type represents such a tag in a type-safe way. It can be constructed from a four-character, 8bit string literal, or from a corresponding 32bit integer value. Using a shorter or longer string literal will result in a compile-time error.

     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);

The named constructors allow to create a tag from an 32bit integer or string value, and will return a `std::nullopt` when the input is invalid.

See also QFont::setFeature() and QFont::featureTags().

## Member Function Documentation

### `[constexpr noexcept]` Tag::Tag()

Default constructor, producing an invalid tag.

### `[constexpr noexcept]` template <size_t N> Tag::Tag(const char (&)[N] str)

Constructs a tag from a string literal, str. The literal must be exactly four characters long.

     font.setFeature("frac", 1);

See also fromString() and fromValue().

### `[static noexcept]` std::optional<QFont::Tag> Tag::fromString(QAnyStringView view)

Returns a tag constructed from the string in view. The string must be exactly four characters long.

Returns `std::nullopt` if the input is not four characters long, or if the tag produced would be invalid.

See also isValid() and fromValue().

### `[static constexpr noexcept]` std::optional<QFont::Tag> Tag::fromValue(quint32 value)

Returns a tag constructed from value, or `std::nullopt` if the tag produced would be invalid.

See also isValid().

### `[constexpr noexcept]` bool Tag::isValid() const

Returns whether the tag is valid. A tag is valid if its value is not zero.

See also value(), fromValue(), and fromString().

### QByteArray Tag::toString() const

Returns the string representation of this tag as a byte array.

See also fromString().

### `[constexpr noexcept]` quint32 Tag::value() const

Returns the numerical value of this tag.

See also isValid() and fromValue().

## Related Non-Members

### `[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)

Compare lhs with rhs for equality and ordering.

### `[constexpr noexcept]` size_t qHash(QFont::Tag key, size_t seed = 0)

Returns the hash value for key, using seed to seed the calculation.