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

QPainter::drawText() background height is not always correct and it doesn't equal the font height on Windows.

    XMLWordPrintable

Details

    • 11189af016c1deeefed476c5cc3a408f6ee79a2d

    Description

      QPainter::drawText() background is 1 pixel higher than the font height i.e. QFontMetrics::height(). If you set the height in QPainter::drawText() the outcome doesn't always follow the setting. In the attached example the font height is 18 pixels and if you set the height of drawText() to 19 or 18 the outcome is 19 pixels, and with 17 it is 17. I.e. the text rectangle is never 18 pixels high.

      The attached example demonstrates this by drawing texts of height 19, 18, 17 and a reference rectangle ( QPainter::drawRect() ) with height 18. The black line is drawn such that the 18 px high rectangle should end on top of it. But as we can see in the attached picture the rectangles of 19 and 18 pixels height end at the bottom of the line.

      The problem was seen also with other font sizes. And it is reproducible only on windows.

      Attachments

        1. qtbug36444.zip
          1 kB
        2. qt5_xcb.png
          qt5_xcb.png
          19 kB
        3. qt5_win.png
          qt5_win.png
          6 kB
        4. qt4_win.png
          qt4_win.png
          5 kB
        5. qt4_linux.png
          qt4_linux.png
          26 kB
        6. DrawTextExample.PNG
          DrawTextExample.PNG
          0.8 kB
        7. DrawTextError.zip
          1 kB

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            qtcomsupport Qt Support
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: