Obtain the pixel height and width of the font in QT.

Source: Internet
Author: User

The following functions are used to calculate the pixel height and width of the font when you use QT for text scrolling:

1. qlabel: fontmetrics (). Width (qstring S): obtains the total pixel width of string S.

Int qfontmetrics: width (const qstring
& Text, Int Len=-1) const

Returns the width in pixels of the first
LenCharactersText. If
LenIs negative (the default), the entire string is used.

Note that this value is
NotEqual to boundingrect (). Width ();
Boundingrect () returns a rectangle describing the pixels this string will cover whereas width () returns the distance to where
Next string shoshould be drawn.

See also boundingrect ().

2. qlabel: fontmetrics (). Height (): Get the font height.

Int qfontmetrics: height () const

Returns the height of the font.

This is always equal
Ascent () + descent () + 1
(The 1 is for the base line ).

See also leading () and
Linespacing ().

3. qlabel: fontmetrics (). linespacing (): Get the font height, including the actual width and line spacing of the text.

4. qlabel: fontmetrics (). Leading (): row spacing

Int qfontmetrics: Leading () const

Returns the leading of the font.

This is the natural inter-line spacing.

See also height () and
Linespacing ().

For other functions, see qfontmetrics class reference of QT.

Int qfontmetrics: linespacing () const

Returns the distance from one base line to the next.

This value is always equal
Leading () + height ().

See also height () and
Leading ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.