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

Some fonts dimensions changed between Qt5 and Qt6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.5
    • GUI: Font handling
    • None
    • Windows, Python 3.10 installed both PySide2 (Qt5) and PySide6 (Qt6) using pip
      4K Monitor, OS scaling set to 100% or 150% will give the same result
    • Windows

    Description

      Reported font height (ascent+descent) as well as character width (QFont::boundingRect) measurements for the same font are different between Qt5 and Qt6.

      Our C++ application relies on on height measurements to define the display layour and because Qt5 and Qt6 are reporting slightly different values, our application UI is not identical between Qt5 and Qt6.

      Difference is not systhematic and apear more often with small fonts. We noticed that both Qt::AA_EnableHighDpiScaling and QGuiApplication::setHighDpiScaleFactorRoundingPolicy affected the reported dimentions but the impact was different between Qt5 and Qt6. Our application disables HighDpiScaling.

      The following PySide code snipset demonstrate the problem. It can be run under python 3.10. Using PySide2 for Qt5 and or PySide6 for Qt6:

      # This example prints the Ascent and Descent dimesiosn for the Segoe UI and Arial size 11 fonts
      # Returned values will differ between Qt 5 and Qt6
      # Edit the next 2 lines (changing for PySide6 to run with Qt6)
      from PySide2.QtCore import Qt, QCoreApplication
      from PySide2.QtGui import QGuiApplication, QFont, QFontMetrics
      QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, False )
      qga = QGuiApplication()
      
      def test( fontName ):
          font = QFont( fontName, -1, QFont.Normal )
          font.setPixelSize( 11 )
          print( "QFont.toString: ", font.toString() )
          fm = QFontMetrics( font )
          print( "A : ", fm.ascent(), " D : ", fm.descent(), "Rec :", fm.boundingRect( "This is a very long text string" ) )
      
      test( "Segoe UI" ) # Qt5 A=11 D=2     QT6 A=12 D=3
      test( "Arial" )    # Qt5 A=11 D=3     Qt6 A=10 D=2
      

      UPDATE: I have attached a C++ implementation of this reproducer .
       

      Attachments

        1. qt5_freetype.png
          qt5_freetype.png
          15 kB
        2. qt5_gdi.png
          qt5_gdi.png
          14 kB
        3. qt6_gdi.png
          qt6_gdi.png
          15 kB
        4. qtbug-117013.7z
          12 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            langlor Richard Langlois
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes