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

QPainterPath::addText produces very different spacing (Windows)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.3
    • GUI: Painting
    • None
    • Windows 10 Home
      Version 20H2
      OS build 19042.928
      Display resolution: 1920x1080
      Scaling: 100%
    • Windows

    Description

      Painting the same text using QPainterPath::addText followed by QPainter::drawPath produces text that has very different spacing from QPainter::drawText with the same font. I have observed this with different font sizes with Verdana font. The example shown here is a particularly bad example.

      This only affects Windows, not Linux or macOS. I'm not using a High DPI display.

      paintwidget.cpp
      #include <QPaintEvent>
      #include <QPainter>
      #include <QPainterPath>
      
      #include "paintwidget.h"
      
      PaintWidget::PaintWidget(QWidget *parent) : QWidget(parent),
            m_font( "Verdana", 14 ),
            m_metrics( m_font )
      {}
      
      QSize PaintWidget::minimumSizeHint() const
      {
          return QSize( 100, 100 );
      }
      
      QSize PaintWidget::sizeHint() const
      {
          return QSize( 400, 200 );
      }
      
      void PaintWidget::paintEvent(QPaintEvent* event)
      {
          Q_UNUSED( event )
      
          QPainter painter( this );
      
          QPointF pos( 10, 10 + m_metrics.ascent() );
          QString text( "iiiiiiiiii" );
      
          painter.setPen( Qt::black );
          painter.setFont(m_font);
          painter.setRenderHint( QPainter::Antialiasing, true );
          painter.drawText( pos,  text );
      
          pos.ry() += m_metrics.lineSpacing();
          QPainterPath path;
          path.addText( pos, m_font, text );
      
          painter.setPen( Qt::transparent );
          painter.setBrush( Qt::black );
          painter.drawPath( path );
      }
      

      On Windows, spacing is very different for the two painting methods:

      On Linux (Kubuntu 18.04), spacing is the same for both methods:

       

      Attachments

        1. linux.png
          9 kB
          Jessica Leigh
        2. windows.png
          2 kB
          Jessica Leigh
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            jleigh Jessica Leigh
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes