Results 1 to 2 of 2

Thread: get exact height of a QString in pixels

  1. #1
    Join Date
    Feb 2009
    Posts
    20

    Default get exact height of a QString in pixels

    Hello!

    How can I get the height of a QString in pixels?
    Using QFontMetric doesn't seam to work.

    I print an "x" and I get via QFontMetric ::size a height of 14, but where the character is only 6 pixels height.
    why is there a 'height()' function in QFontMetric without QString argument, every character has a different height.

    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: get exact height of a QString in pixels

    It only returns the height of the used font. The string parameter is useful if you have line breaks in it.

    To measure the actual height I can only thing of that nasty solution: Paint the string to a white pixmap and count all lines which only have white pixels. so you can get the absolute height of your character.

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. Replies: 2
    Last Post: 14th May 2010, 14:12
  3. Pixels
    By Dante in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2009, 20:50
  4. exact region of drawn part
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 18:07
  5. Replies: 4
    Last Post: 31st January 2008, 20:44

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.