QFontMetrics is a class in Qt library that provides information about the metrics and geometry of fonts. One of its member functions is 'descent,' which returns the distance from the baseline to the bottom of the font's bounding rectangle.
Example 1: Suppose we have a label 'myLabel' with font size 14 and text "Hello World!" We can use QFontMetrics to determine the descent of the font and position the label accordingly:
Explanation: We create a QFont object with the desired font family and size. We then pass this font to QFontMetrics to get the metrics of the font. We store the descent of the font in a variable 'descent.' Finally, we move the label by subtracting the descent from the desired y-coordinate of 50.
Example 2: Suppose we have a document editor that supports custom fonts. We want to display a preview of the font with its name and descent value. We can use QFontMetrics to get information about the font, including its descent:
Explanation: We create a QFont object with the desired font family and size. We pass this font to QFontMetrics to get its metrics. We store the font name in a variable 'fontName' and the descent in 'descent.' We can then print this information or use it as needed.
Package/Library: This code uses the QFontMetrics class, which is part of the Qt library.
C++ (Cpp) QFontMetrics::descent - 26 examples found. These are the top rated real world C++ (Cpp) examples of QFontMetrics::descent extracted from open source projects. You can rate examples to help us improve the quality of examples.