doc: Clarify usage of QFontMetricsF instead of QFontMetrics

A common source of issues is that people do not consider that
fonts can have fractional metrics and use QFontMetrics for UI
purposes, causing bounds and eliding to be inaccurate.

This is not very surprising, since the class name sounds very
much like what you should prefer by default and the docs
didn't even contain links to the QFontMetricsF class.

It might make sense to deprecate the class, since it really
does not serve any useful purpose, but for now we at least
document the issue up-front so that users can easily find
the alternative.

Pick-to: 6.5
Task-number: QTBUG-132102
Change-Id: I69756c561e5dee448a9d0a7d85af1a9b15ff1ae3
Reviewed-by: Nodir Temirkhodjaev <nodir.temir@gmail.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 9a6036dea2cfe0cec555a503445aed93fed3d985)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 51ed0b024b35f1daa67ac8d129d16dabb6bba2c9)
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2024-12-16 08:45:38 +01:00 committed by Qt Cherry-pick Bot
parent c876e78719
commit 982ce114ca

View File

@ -31,8 +31,13 @@ extern void qt_format_text(const QFont& font, const QRectF &_r,
\ingroup shared
QFontMetrics functions calculate the size of characters and
strings for a given font. There are three ways you can create a
QFontMetrics object:
strings for a given font. The class is an integer-based version
of QFontMetricsF and will round all numbers to the nearest
integer. This means its results will be inaccurate for any font
with fractional metrics. In most cases QFontMetricsF should be
used instead.
There are three ways you can create a QFontMetrics object:
\list 1
\li Calling the QFontMetrics constructor with a QFont creates a