Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-93472

QPainter::drawText() on QPixmap does not produce ClearType subpixel anti-aliasing

    XMLWordPrintable

Details

    • Windows

    Description

      QPainter::drawText() on QWidget produces correctly ClearType subpixel anti-aliased result.
      However, QPainter::drawText() on QPixmap produces gray-scale subpixel anti-aliased image which results into blurry image.

      Same result for both of Qt 5.15.2 and Qt 6.0.4.

      Here's sample code to reproduce the problem:

      #include <QtWidgets/QWidget>
      #include <QtWidgets/QApplication>
      #include <QtGui/QPainter>
      
      namespace {
      
      class DirectWidget : public QWidget {
      public:
          DirectWidget() noexcept { setFixedSize(150, 20); }
      private:
          auto paintEvent(QPaintEvent *) -> void final
          {
              QPainter painter{this};
              painter.setRenderHint(QPainter::TextAntialiasing);
              painter.drawText(rect(), Qt::AlignCenter, "Direct Rendering");
          }
      };
      
      class PixmapWidget : public QWidget {
      public:
          PixmapWidget() noexcept { setFixedSize(150, 20); }
      private:
          auto paintEvent(QPaintEvent *) -> void final
          {
              QPixmap pixmap{size()};
              pixmap.fill(Qt::transparent);
              QPainter painter{&pixmap};
              painter.setRenderHint(QPainter::TextAntialiasing);
              painter.drawText(pixmap.rect(), Qt::AlignCenter, "Pixmap Rendering");
              painter.end();
              painter.begin(this);
              painter.drawPixmap(0, 0, pixmap);
          }
      };
      
      }
      
      auto main(int argc, char **argv) -> int
      {
          QApplication app{argc, argv};
          app.setFont(QFont{"Consolas"});
          DirectWidget dw;
          dw.show();
          PixmapWidget pw;
          pw.show();
          return app.exec();
      }
      

      You can see the problem in attachments, especially in enlarged screenshot.

      Attachments

        1. subpixel-s.png
          subpixel-s.png
          3 kB
        2. subpixel.png
          subpixel.png
          42 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            xylosper Byoung-young Lee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes