How to save text antialiasing on QImage?

  • If I draw text on QImage and then show it via QPainter on QWidget I get bad antialiasing compared to direct text drawing via QPainter.

    Here is simple code example:
    @#include <QApplication>
    #include <QtGui>

    class Widget : public QWidget

    Widget(QWidget *parent = 0) : QWidget(parent)
    m_img = QImage(QSize(200, 50), QImage::Format_ARGB32_Premultiplied);
    QPainter p(&m_img);
    p.fillRect(m_img.rect(), palette().color(QPalette::Active, QPalette::Window));
    p.setPen(palette().color(QPalette::Active, QPalette::Text));
    p.drawText(m_img.rect(), Qt::AlignCenter, "My Text 11~!");

        setFixedSize(200, 100);
    void paintEvent(QPaintEvent *)
        QPainter p(this);
        p.fillRect(rect(), palette().color(QPalette::Active, QPalette::Window));
        p.drawImage(0, 0, m_img);
        p.fillRect(0, 50, 200, 1, Qt::red);
        p.drawText(QRect(0, 50, 200, 50), Qt::AlignCenter, "My Text 11~!");

    QImage m_img;

    #include "main.moc"

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    Widget w;;
    return a.exec();

    Linux, KDE, Font: Verdana 11, Slight hinting, RGB subpixel rendering.

    Example (orig):
    Example (800% scale):

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.