KFontUtils Namespace

Provides utility functions for font data. More...

Header: #include <KFontUtils>
CMake: find_package(KF6 REQUIRED COMPONENTS GuiAddons)
target_link_libraries(mytarget PRIVATE KF6::GuiAddons)

Types

enum AdaptFontSizeOption { NoFlags, DoNotAllowWordWrap }
flags AdaptFontSizeOptions

Functions

(since 4.7) qreal adaptFontSize(QPainter &painter, const QString &text, const QSizeF &availableSize, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, KFontUtils::AdaptFontSizeOptions flags = NoFlags)
(since 4.7) qreal adaptFontSize(QPainter &painter, const QString &text, qreal width, qreal height, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, KFontUtils::AdaptFontSizeOptions flags = NoFlags)

Detailed Description

Type Documentation

enum KFontUtils::AdaptFontSizeOption
flags KFontUtils::AdaptFontSizeOptions

Modifiers for the adaptFontSize function

ConstantValueDescription
KFontUtils::NoFlags0x01No modifier
KFontUtils::DoNotAllowWordWrap0x02Do not use word wrapping

The AdaptFontSizeOptions type is a typedef for QFlags<AdaptFontSizeOption>. It stores an OR combination of AdaptFontSizeOption values.

See also AdaptFontSizeOptions.

Function Documentation

[since 4.7] qreal KFontUtils::adaptFontSize(QPainter &painter, const QString &text, const QSizeF &availableSize, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, KFontUtils::AdaptFontSizeOptions flags = NoFlags)

Convenience function for adaptFontSize that accepts a QSizeF instead two qreals

This function was introduced in 4.7.

[since 4.7] qreal KFontUtils::adaptFontSize(QPainter &painter, const QString &text, qreal width, qreal height, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, KFontUtils::AdaptFontSizeOptions flags = NoFlags)

Helper function that calculates the biggest font size (in points) used drawing a centered text using word wrapping.

painter The painter where the text will be painted. The font set in the painter is used for the calculation. Note the painter font size is modified by this call

text The text you want to draw

width The available width for drawing

height The available height for drawing

maxFontSize The maximum font size (in points) to consider

minFontSize The minimum font size (in points) to consider

flags The modifiers for how the text is painted

Returns the calculated biggest font size (in points) that draws the text in the given dimensions. Can return smaller than minFontSize, that means the text doesn't fit in the given rectangle. Can return -1 on error

This function was introduced in 4.7.