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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.3.0 Alpha
    • 4.6.1, 6.2.0
    • GUI: Text handling
    • None
    • 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
        2. qtbug-7768-qt6.tgz
          1 kB
        3. Screenshot_20210514_003635.png
          Screenshot_20210514_003635.png
          98 kB
        4. Screenshot_20211014_120927.png
          Screenshot_20211014_120927.png
          92 kB
        5. text1.jpeg
          text1.jpeg
          10 kB
        6. text2.jpeg
          text2.jpeg
          11 kB

        Issue Links

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

          Activity

            People

              allan.jensen Allan Sandfeld Jensen
              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