Results 1 to 3 of 3

Thread: How do I calculate the height of rendered HTML text in a QTextEdit ?

  1. #1
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I calculate the height of rendered HTML text in a QTextEdit ?

    I want to render linenumbers to the left of a QTextEdit; not just simple single font situation, but when there is a mix of fonts. So how do I calculate the height for each line of HTML text; where to place a QLabel with the line number ?

    I thought of finding the height of the biggest char/font item used in a line of HTML text. Something like

    qreal lineheight_line3 = lineHeightfromHTML( QString( "<h1>Hello</h1><p font="Verdena" size=8>world</p>" );

    Or better something that returns an array of all fonts used per line, which then could be inspected with QFontMetric. But actually I already fail to find the api function that can give me individual lines of a QTextEdit, not just the plain text.

    Thanks in advance,
    Mu

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How do I calculate the height of rendered HTML text in a QTextEdit ?

    Here's one way: http://websvn.kde.org/trunk/KDE/kdel...pathrev=521795. This has been discussed on the forums before as well. Doing a search might help.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I calculate the height of rendered HTML text in a QTextEdit ?

    Thank you,

    you SOLVED it.

    PS: The solution is elegant as well, since it is not required to iterate through all styles/Fonts of a line, as I would have expected; the boundingRect gives enough information to place the line number marks.



    Mu

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. put html text into a qtextedit
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2008, 20:44
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05

Tags for this Thread

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.