Results 1 to 2 of 2

Thread: How to get the line height of a QTextBlock?

  1. #1
    Join Date
    Jan 2013
    Posts
    9
    Thanks
    3
    Qt products
    Qt4

    Question How to get the line height of a QTextBlock?

    Windows 7 SP1
    MSVS 2010
    Qt 4.8.4

    Given this code:

    Qt Code:
    1. #include <QTGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QTextDocument* text_document = new QTextDocument("testing");
    6. QTextBlock text_block = text_document->begin();
    7. qDebug() << text_block.text() << text_block.blockFormat().lineHeight()
    8. << text_block.blockFormat().lineHeightType();
    9. }
    To copy to clipboard, switch view to plain text mode 

    The console displays:

    "testing" 0 0

    Question: Why doesn't lineHeight return "the LineHeight property for the paragraph"? The lineHeightType is set for single spacing.

    Even trying:

    Qt Code:
    1. qDebug() << text_block.text() << text_block.layout()->boundingRect().height();
    To copy to clipboard, switch view to plain text mode 

    gives me zero.

  2. #2
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get the line height of a QTextBlock?

    QFontMetrics fm(font);//set to any font =>font.setFamily("Arial"); font.setPointSize(10);
    int yCharOffset = 4;
    int lineHeight = fm.boundingRect('W').height() + 2 * yCharOffset;
    int xCharOffset = 1;
    int charWidth = fm.boundingRect('W').width() + 2 * xCharOffset;

Similar Threads

  1. QLABEL how to Set Line Height?
    By lamp in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2010, 12:22
  2. Changing line height in QTextEdit (Qt4)
    By ultr in forum Qt Programming
    Replies: 0
    Last Post: 19th February 2010, 15:59
  3. QTextBlock::setVisible()
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2009, 01:06
  4. QTextDocument and line height
    By vooft in forum Qt Programming
    Replies: 0
    Last Post: 25th November 2008, 16:47
  5. QTextEdit and QTextBlock
    By Garfeild in forum Qt Programming
    Replies: 10
    Last Post: 26th April 2008, 10:32

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.