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. QFontMetrics::boundingRect() returns wrong text width
Forum Updated to NodeBB v4.3 + New Features

QFontMetrics::boundingRect() returns wrong text width

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.0k 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.
  • D Offline
    D Offline
    DenProg
    wrote on 11 Apr 2013, 06:45 last edited by
    #1

    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
    0

    1/1

    11 Apr 2013, 06:45

    • Login

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