Results 1 to 2 of 2

Thread: QFontMetrics and HTML tags

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QFontMetrics and HTML tags

    I have many pop-up information panels (QLabels) with text (QStrings). I set the Label width myself, and use QFontMetrics to determine the height.

    I've been using "\n" in places where I want to insert a line break. No problem, QFontMetrics handles this fine. I've just discovered that I can use HTML tags (i.e. <b> <i> <font size="+1"> <br>) to modify the text. Unfortunately, "\n" and the HTML tags are not compatable. For a given string, if "\n" appears first, then the HTML tags won't work... and vice-versa.

    I could use <br> instead of "\n" for my line breaks... but when I do this, QFontMetrics doesn't pick up on it and my text gets cut-off at the bottom of the Label. Easy fix? (besides counting the number of <br>'s in a given text string and adding that to the QLabel's height. If I have to do something like this: I do I determine the height of a single <br>?)

    ...or... is there another syntax/tag I can use besides HTML that would work better?

    thanks

  2. #2
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFontMetrics and HTML tags

    nevermind, i did just that: count the number of "<br>", do a simple fontMet.height(), and multiply/add that to the Label height.





    ps: although, just to test... I bracketed my text in

    Qt Code:
    1. <font size="+1">...long paragraph here...</font>
    To copy to clipboard, switch view to plain text mode 

    just to see what would happen, and as expected QFontMetrics didn't pick up on the change in font size (and the text was cut off at the bottom... but not on the right). I wonder if there's a way to make QFontMetrics take into account HTML tags.
    Last edited by vonCZ; 14th August 2008 at 12:32.

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.