Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to get the line height of a QTextBlock?

    General and Desktop
    1
    1
    1022
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Therefore last edited by

      Windows 7 SP1
      MSVS 2010
      Qt 4.8.4

      Given this code:

      @#include <QTGui>

      int main(int argc, char argv[])
      {
      QTextDocument
      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):

      @text_block.blockFormat().setLineHeight(30,QTextBlockFormat::SingleHeight);@

      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.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post