I want to draw text using QPainter
, and I want to use QPainterPath
first (because ultimately I want to rotate the text in all sorts of ways). However, I find that the text produced by QPainterPath
is much uglier than the text produced by QPainter
.
The following code:
void MyWidget::paintEvent(QPaintEvent* /*event*/) {
QFont font;
font.setStyleHint(QFont::Times, QFont::PreferAntialias);
font.setPointSize(30);
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(Qt::black);
painter.setFont(font);
painter.drawText(10, 40, "Hello World");
QPainterPath textPath;
textPath.addText(10, 100, font, "Hello world");
painter.drawPath(textPath);
painter.end();
}
produces the following result:
The former is clearly much cleaner and nicer, especially in smaller fonts. What should I do to get the same result from QPainterPath
?
I'm producing the above results on a Windows 7 computer, with Qt 5.0.