Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.3
-
None
-
Windows 10 Home
Version 20H2
OS build 19042.928
Display resolution: 1920x1080
Scaling: 100%
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: