FIL
FIL

Reputation: 41

QPainter.drawText ugly font rendering

qfont = QtGui.QFont('Ubuntu', 9)
#qfont.setHintingPreference(QtGui.QFont.PreferDefaultHinting)
#qfont.setStyleStrategy(QtGui.QFont.PreferAntialias)
qfont.setStyle(QtGui.QFont.StyleNormal)
qfont.setWeight(QtGui.QFont.Normal)
qpaint.setFont(qfont)
qpaint.drawText(qpix.rect() , QtCore.Qt.AlignBottom + QtCore.Qt.AlignCenter, Invent.get_item(i)['type'])

Font rendering (anti-aliasing) is different from the one used by other applications.

http://rghost.net/53129449/image.png

How do I make it look the same?

Upvotes: 4

Views: 1960

Answers (1)

Nicolas Holthaus
Nicolas Holthaus

Reputation: 8273

I'm not sure if this applies directly to pyQt, but on the c++ side render hints need to be set anytime the painting is scaled or it will look bad. Here's how I set my flags:

m_paintFlags = QPainter::RenderHint(QPainter::Antialiasing | 
    QPainter::SmoothPixmapTransform | 
    QPainter::HighQualityAntialiasing);

Then, in the paint event before drawing anything:

painter.setRenderHints(m_paintFlags);

Upvotes: 1

Related Questions