Results 1 to 1 of 1

Thread: Lineheight of QPainter vs. QSyntaxHighlighter

  1. #1
    Join Date
    Jul 2012
    Posts
    182
    Thanks
    9
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Lineheight of QPainter vs. QSyntaxHighlighter

    Here is the situation: I have a text string spanning several lines like so

    Qt Code:
    1. QString str = "111111\n 222222\n 333333\n";
    To copy to clipboard, switch view to plain text mode 


    Depending on whether I draw it with a plain QPainter or via a QSyntaxHighlighter, I get different lineheights.
    As a result, when drawn next to each other, the lines dont match up.


    Qt Code:
    1. qpainter.setFont(fixed_font);
    2. qpainter.drawText(rect(), Qt::AlignLeft|Qt::AlignTop, str);
    3.  
    4. vs.
    5.  
    6. qsyntaxhighlighter.setFont(fixed_font);
    7. qsyntaxhighlighter.setText(str);
    8. qsyntaxhighlighter.drawFormattedText(qpainter, rect());
    To copy to clipboard, switch view to plain text mode 


    Namely the lineheight of the text drawn by the plain qpainter is smaller than that drawn by QSyntaxHighlighter, just by one pixel or so.

    I suspect that QPainter is somehow using QFontMetric::lineSpacing() while QSyntaxHighlighter is using QFontMetric::height(). They are 7, resp. 8 on my system and would nicely explain the difference I am seeing.

    How can I work around this? Is this a bug?



    Environment: Qt 5.11, Ubuntu 17.10, fixed_font = QFontDatabase::systemFont(QFontDatabase::FixedFont )
    Last edited by tuli; 9th June 2018 at 01:50.

Similar Threads

  1. QSyntaxHighlighter: backgroundhighlighting
    By tuli in forum Qt Programming
    Replies: 0
    Last Post: 10th September 2012, 14:30
  2. Using QSyntaxHighlighter
    By chris_helloworld in forum Qt Programming
    Replies: 0
    Last Post: 5th October 2010, 11:22
  3. Replies: 2
    Last Post: 9th November 2009, 16:40
  4. lineheight in QwwFileChooser (wwidgets)
    By pospiech in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2009, 19:39
  5. QSyntaxHighlighter and faked currentParagraph()
    By mcostalba in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2008, 00:36

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.