Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does QPainter::TextAntialiasing doesn't work in my code?
Qt 6.11 is out! See what's new in the release blog

Why does QPainter::TextAntialiasing doesn't work in my code?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mireiner
    wrote on last edited by mireiner
    #1

    Hi there,

    on Windows 10 desktop I have the feeling that text antialiasing does not work in my Qt 5.7.0 code. I can not see any difference between the following first two Qt based screenshots. But in the third one, done with Visual C#, antialiasing works:

    Load them in different browser tabs and switch between them:
    https://s19.postimg.org/4321qkavn/Qt_5_7_0_no_antialiasing.png
    https://s19.postimg.org/rijyvwum/Qt_5_7_0_with_antialiasing.png
    https://s19.postimg.org/4or0mo5xv/Visual_C.png

    Look for example at the letters 'S' or 'a'. The last Visual C# based screenshot look a lot smoother, whereas both Qt screenshots look the same pixelated.

    Please look at my code. Why text antialiasing doesn't work? What's wrong in my code?

    Is there anything else beside the code to consider on Windows to make text antialiasing work?

    #include <QApplication>
    #include <QWidget>
    #include <QPainter>
    
    class Widget : public QWidget
    {
    public:
    	Widget();
    
    protected:
    	void paintEvent(QPaintEvent *);
    };
    
    Widget::Widget()
    {
    	setAutoFillBackground(true);
    	setPalette(Qt::white);
    }
    
    void Widget::paintEvent(QPaintEvent *)
    {
    	QPainter painter(this);
    
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.setRenderHint(QPainter::TextAntialiasing, true);
        painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
    
        QFont Roboto("Roboto", 24, QFont::Normal);
        QFont SourceSansPro("Source Sans Pro", 24, QFont::Normal);
        QFont ClearSans("Clear Sans", 24, QFont::Normal);
        QFont Ubuntu("Ubuntu", 24, QFont::Normal);
        QFont SegoeUI("SegoeUI", 24, QFont::Normal);
    
        painter.setFont(Roboto);
        painter.drawText(QPointF(20.0, 60.0), "Qt 5.7.0 on Windows Desktop: with anti aliasing:");
        painter.drawText(QPointF(20.0, 140.0), "The quick brown fox jumps over the lazy dog: Roboto");
        painter.setFont(SourceSansPro);
        painter.drawText(QPointF(20.0, 220.0), "The quick brown fox jumps over the lazy dog: Source Sans Pro");
        painter.setFont(ClearSans);
        painter.drawText(QPointF(20.0, 300.0), "The quick brown fox jumps over the lazy dog: Clear Sans");
        painter.setFont(Ubuntu);
        painter.drawText(QPointF(20.0, 380.0), "The quick brown fox jumps over the lazy dog: Ubuntu");
        painter.setFont(SegoeUI);
        painter.drawText(QPointF(20.0, 460.0), "The quick brown fox jumps over the lazy dog: SegoeUI");
    }
    
    int main(int argc, char *argv[])
    {
    	QApplication app(argc, argv);
    	Widget widget;
    	widget.showMaximized();
    	return app.exec();
    }
    
    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      antialiasing != antialiasing
      Means there are different strategies do achieve antialiasing and the result may differ.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        And your second link is broken ... it says the image was unavailable/removed.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Praveen kk
          wrote on last edited by Praveen kk
          #4

          As per my understanding by default QPainter paints with anti-aliasing feature.
          Any way can you try this..?

          QFont Roboto("Roboto", 24, QFont::Normal);
          Roboto.setStyleStrategy(QFont::PreferAntialias);
          painter.setFont(Roboto);
          painter.drawText(QPointF(20.0, 60.0), "Qt 5.7.0 on Windows Desktop: with anti aliasing:");

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved