Skip to content

PythonQt.QtGui.QFontMetricsF

QFontMetricsF

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QFontMetricsF functions calculate the size of characters and strings for a given font. You can construct a QFontMetricsF object with an existing QFont to obtain metrics for that font. If the font is changed later, the font metrics object is not updated.

Once created, the object provides functions to access the individual metrics of the font, its characters, and for strings rendered in the font.

There are several functions that operate on the font: ascent(), descent(), height(), leading() and lineSpacing() return the basic size properties of the font. The underlinePos(), overlinePos(), strikeOutPos() and lineWidth() functions, return the properties of the line that underlines, overlines or strikes out the characters. These functions are all fast.

There are also some functions that operate on the set of glyphs in the font: minLeftBearing(), minRightBearing() and maxWidth(). These are by necessity slow, and we recommend avoiding them if possible.

For each character, you can get its horizontalAdvance(), leftBearing(), and rightBearing(), and find out whether it is in the font using inFont(). You can also treat the character as a string, and use the string functions on it.

The string functions include horizontalAdvance(), to return the width of a string in pixels (or points, for a printer), boundingRect(), to return a rectangle large enough to contain the rendered string, and size(), to return the size of that rectangle.

Example:

QFont font("times", 24);
QFontMetricsF fm(font);
qreal pixelsWide = fm.horizontalAdvance("What's the width of this text?");
qreal pixelsHigh = fm.height();

Source: https://doc.qt.io/archives/qt-5.15/qfontmetricsf.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
ascent function (self) -> float X.ascent() -> float
averageCharWidth function (self) -> float X.averageCharWidth() -> float
boundingRect function (self, r: Any, arg1: flags, string: str, tabstops: Any, tabarray: Any) -> Any X.boundingRect(r, flags, string, tabstops, tabarray) -> PythonQt.QtCore.QRectF
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
descent function (self) -> float X.descent() -> float
elidedText function (self, text: str, mode: Any, width: float, arg3: flags) -> str X.elidedText(text, mode, width, flags) -> str
height function (self) -> float X.height() -> float
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inFont function (self, arg__1: str) -> bool X.inFont(arg__1) -> bool
inFontUcs4 function (self, ucs4: int) -> bool X.inFontUcs4(ucs4) -> bool
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
leading function (self) -> float X.leading() -> float
leftBearing function (self, arg__1: str) -> float X.leftBearing(arg__1) -> float
lineSpacing function (self) -> float X.lineSpacing() -> float
lineWidth function (self) -> float X.lineWidth() -> float
maxWidth function (self) -> float X.maxWidth() -> float
minLeftBearing function (self) -> float X.minLeftBearing() -> float
minRightBearing function (self) -> float X.minRightBearing() -> float
overlinePos function (self) -> float X.overlinePos() -> float
rightBearing function (self, arg__1: str) -> float X.rightBearing(arg__1) -> float
size function (self, arg0: flags, str: str, tabstops: int, tabarray: Any) -> Any X.size(flags, str, tabstops, tabarray) -> PythonQt.QtCore.QSizeF
strikeOutPos function (self) -> float X.strikeOutPos() -> float
swap function (self, other: Any) -> None Swaps this font metrics instance with other.
tightBoundingRect function (self, text: str) -> Any X.tightBoundingRect(text) -> PythonQt.QtCore.QRectF
underlinePos function (self) -> float X.underlinePos() -> float
width function (self, arg__1: Any) -> float X.width(arg__1) -> float
xHeight function (self) -> float X.xHeight() -> float