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

QLabel::fontMetrics().boundingRect(text) != rendered width for some fonts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.12.0
    • None
    • Linux/X11

    Description

      With some fonts the width of the boundingRect as returned by QFontMetrics as got from the actual QLabel object seems to be out of sync with the width of what is actually rendered inside the QLabel.
      Which breaks e.g. code which relies on the boundingRect to calculate some fixed size for a label widget.

      Please find attached a sample program which should show the effect. Build & run it with:

      qmake && make
      ./notometrics [fontfamily] [-f])
      

      fontfamily defaults to "Noto Sans"
      -f to set the label to the fixedsize as calculated via boundingRect

      For fonts like "Liberation Sans" or "Droid Sans" the widths were identical.

      For "Noto Sans" though things were out of sync by quite some pixels:

      Which is quite surprising and seems like a bug, given the very QFontMetrics object was used that has been fetched from the very QLabel object, which by a quick look internally in the QLabel codebase at least in some path also seems to rely on that very QFontMetrics object.

      Attachments

        1. main.cpp
          1 kB
        2. notometrics.pro
          0.1 kB
        3. Screenshot_20190114_023300.png
          Screenshot_20190114_023300.png
          25 kB

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              kossebau Friedrich W. H. Kossebau
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: