Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the line height of a QTextBlock?
Qt 6.11 is out! See what's new in the release blog

How to get the line height of a QTextBlock?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • 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 Offline
    T Offline
    Therefore
    wrote on last edited by
    #1

    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
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved