Qt Forum

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

    QFontMetrics::boundingRect() returns wrong text width

    General and Desktop
    1
    1
    1899
    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.
    • D
      DenProg last edited by

      I want to get a text width. I need to know this width before rendering of the text.
      So I do:
      @QFontMetrics m(font);
      QRectF b1 = m.boundingRect(QRect(0, 0, 0, 0), Qt::AlignCenter, text);@

      After that when I render this text I do:

      @painter->setFont(font);
      QRectF b2 = painter->boundingRect(QRect(0, 0, 0, 0), Qt::AlignCenter, text);@

      font and text are the same. But I get different width. Why and how can I get the same one?

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