Results 1 to 9 of 9

Thread: QFontMetrics.height()

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFontMetrics.height()

    Hello,
    it is possible to compute the exact width of a string using QFontMetrics.width(QString) but surprisingly it is nt possible to get its height as well since only QFontMetrics.height() is available, which returns some maximum height of a string using a given font. Is it possible to compute the real height of a given string, ie some QFontMetrics.height(QString) functionality?

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics.height()

    why would u need that..QFontMetrics.height() would return the same thing as QFontMetrics.height(QString) would, if there was any...

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFontMetrics.height()

    Quote Originally Posted by talk2amulya View Post
    why would u need that..QFontMetrics.height() would return the same thing as QFontMetrics.height(QString) would, if there was any...
    In your opinion, is the height of any string the same? For instance is the height of "oo" the same as the height of "lp"?

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics.height()

    function returns the maximum height possible..it gives the sum of ascent, descent .. which are highest position and lowest position a character can get to respectively..plus 1..so yeh, height returned for any string would be same.

  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFontMetrics.height()

    Quote Originally Posted by talk2amulya View Post
    function returns the maximum height possible..it gives the sum of ascent, descent .. which are highest position and lowest position a character can get to respectively..plus 1..so yeh, height returned for any string would be same.
    Just try to answer to mu previous question and you should be able to understand that you are wrong.

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics.height()

    no point arguing about it , i believe i m right here , if you were right, Qt would have included such a function..anyways, u could also check boundingRect(), it takes a string argument..but again, it also returns height AT LEAST that is returned by height()

  7. #7
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFontMetrics.height()

    Quote Originally Posted by talk2amulya View Post
    no point arguing about it , i believe i m right here , if you were right, Qt would have included such a function..
    but Qt developpers might not thinking about specific cases, such as when all characters are in CAPS, and in this case no one goes below the baseline, which leads to a wrong measure. So since they have developped a way to evaluate string width, it was probably not that difficult to provide a similar functionaliy for height.

  8. #8
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics.height()

    i guess for that the best bet u have is boundingRect(QString)...it will give u the height as it is..and it shouldnt affect your program much..its better than to curse Qt whole day ..ciao

  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics.height()

    Height is basically for the whole string, so its logical for it to be same.
    However, font metrics dont consist of just height, there are also ascent and descent.(QFontMetrics::ascent,QFontMetrics::descent).

    Have a look at them too.

    Also there was som example related to fonts on Qt Labs.. Font Anatomy. I think on SVN, under graphics directory. Have a look at it too, it might help

Bookmarks

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.