Results 1 to 1 of 1

Thread: QFont pixelSize and QFontMetrics height give different values

  1. #1
    Join Date
    Jul 2010
    Qt products

    Default QFont pixelSize and QFontMetrics height give different values

    I am creating a custom label and want it to have a 13 pixel high text and setting label's max height to 14.

    textFont.setFamily("Frutiger LT Com 55 Roman");
    QFontMetrics fm(this->font());
    QFontInfo fi(this->font());
    qDebug()<<"QFontMetrics"<<fm.height()<<fm.xHeight( )<<fm.ascent()<<fm.descent();
    qDebug()<<"QFontInfo"<<fi.exactMatch()<< )<<fi.pixelSize();

    This is what I get

    QFontMetrics 16 3 13 3
    QFontInfo true "Frutiger LT Com 55 Roman" 13
    Why am I getting height as "16" when I am setting pixelSize as "13"? And because of this text on my label is getting clipped from bottom (Vertically center aligned).

    QFontMetrics "height()" definition says height=ascent+descent+1(for baseline). But as you can see above ascent=13, descent=3 and height=16. This contradicts "height()" function definition.
    Last edited by nets; 3rd February 2014 at 17:11.

Similar Threads

  1. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  2. Replies: 3
    Last Post: 13th May 2010, 08:20
  3. Stylesheet and QFontMetrics
    By ucomesdag in forum Qt Programming
    Replies: 7
    Last Post: 18th January 2010, 07:45
  4. QFontMetrics.height()
    By Caius Aérobus in forum Qt Programming
    Replies: 8
    Last Post: 4th April 2009, 17:36
  5. QFontMetrics, i can't understand
    By pakulo in forum Qt Programming
    Replies: 11
    Last Post: 24th June 2007, 17:59

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.