Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-7768

fontMetrics.boundingRect() and drawText(boundingRect) disagree about text width metrics

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 4.6.1, 6.2.0
    • Fix Version/s: 6.3.0 Alpha
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Commits:
      4748369eb2e458e12f5228a113b9a6dda440b24b (qt/tqtc-qtbase/dev)

      Description

      When I use

      QRect bounds = QFontMetrics.boundingRect(0, 0, maxWidth, 0, Qt::TextWordWrap, string);

      the resulting bounds rectangle is not always big enough to render the same string using the call

      drawText(bounds, Qt::TextWordWrap, string);

      because those two functions use different algorithms to calculate the font width metrics that affect the word break position.

      In the first attached screen shot, the bounding rectangle of the string "Effets de bureau" is used to draw the text, which gets then cropped to "Effets de".

      In the second screen shot, the bounding rectangle returned by QFontMetrics is enlarged by 2 pixels in width, and drawText() now renders the string
      correctly.

      This bug depends on used font, font size, server DPI, and actual text, so no test case to reproduce.

        Attachments

        1. fontmetrics-width-italicfont.cpp
          3 kB
          David Faure
        2. qtbug-7768-qt6.tgz
          1 kB
          Shawn Rutledge
        3. Screenshot_20210514_003635.png
          98 kB
          David Faure
        4. Screenshot_20211014_120927.png
          92 kB
          Allan Sandfeld Jensen
        5. text1.jpeg
          10 kB
          Christoph Feck
        6. text2.jpeg
          11 kB
          Christoph Feck

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              allan.jensen Allan Sandfeld Jensen
              Reporter:
              cfeck Christoph Feck
              Votes:
              5 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes