Important: Please read the Qt Code of Conduct -

How to get the line height of a QTextBlock?

  • Windows 7 SP1
    MSVS 2010
    Qt 4.8.4

    Given this code:

    @#include <QTGui>

    int main(int argc, char argv[])
    text_document = new QTextDocument("testing");
    QTextBlock text_block = text_document->begin();
    qDebug() << text_block.text() << text_block.blockFormat().lineHeight()
    << text_block.blockFormat().lineHeightType();

    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.

    I am clearly not understanding this. When I try to set the line height before outputting, nothing happens (lineHeight() is still zero):


    To be clear, in my application nothing happens when outputting to a GUI window.

    Even trying:

    @qDebug() << text_block.text() << text_block.layout()->boundingRect().height();@

    yields 0.

Log in to reply