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

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



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


      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.


        1. main.cpp
          1 kB
          Friedrich W. H. Kossebau
        2. notometrics.pro
          0.1 kB
          Friedrich W. H. Kossebau
        3. Screenshot_20190114_023300.png
          25 kB
          Friedrich W. H. Kossebau

        Issue Links

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



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



                Gerrit Reviews

                  There are no open Gerrit changes