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. QPainter::DrawText antialiasing not work

QPainter::DrawText antialiasing not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 801 Views
  • 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.
  • jronaldJ Offline
    jronaldJ Offline
    jronald
    wrote on last edited by jronald
    #1

    Env

    Linux KDE
    Qt 6.3.0

    Screenshot

    b48da44f-e418-4512-85f5-0a501aa46d6e-image.png

    Code

    QPixmap pixmap(page_size);
    painter.begin(&pixmap);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    font.setStyleStrategy(QFont::PreferAntialias);
    font.setHintingPreference(QFont::PreferFullHinting);
    painter.setFont(font);
    painter.drawText(text_origin, qs_text);
    painter.end();
    

    More Info

    A similar post: https://forum.qt.io/topic/111322/high-dpi-support-qpainter-drawtext
    It doens't solve the problem for me.

    Question

    How to draw everything antialiasing in Qt6?

    1 Reply Last reply
    0
    • ralienppR Offline
      ralienppR Offline
      ralienpp
      wrote on last edited by
      #2

      It could be related to the fact that you're drawing it on a QPixMap: https://bugreports.qt.io/browse/QTBUG-22334.

      Do you use DPI scaling in your desktop environment? If yes, with what setting?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Since you have taken a screenshot rather than inspected the actual QPixmap you are subject to whatever scaling happened putting the image on the screen. If that scaling up in size is not a nice ratio then you will see it. What is in the actual pixmap?

        This code with Qt 6.2.3 on Linux:

        #include <QGuiApplication>
        #include <QFont>
        #include <QPixmap>
        #include <QPainter>
        
        int main(int argc, char **argv) {
                QGuiApplication app(argc, argv);
        
                QFont font("Verdana");
                QPoint text_origin(50, 20);
                QString qs_text("890,321,832.65");
        
                QPixmap pixmap(800, 600);
                pixmap.fill();
                QPainter painter;
                painter.begin(&pixmap);
                painter.setPen(Qt::green);
                painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
                font.setStyleStrategy(QFont::PreferAntialias);
                font.setHintingPreference(QFont::PreferFullHinting);
        
                for (int size = 8; size < 40; size += 2) {
                        font.setPointSize(size);
                        painter.setFont(font);
                        painter.drawText(text_origin, qs_text);
        
                        QFontMetrics fm(font);
                        painter.translate(0, fm.lineSpacing());
                }
        
                painter.end();
        
                pixmap.save("test.png");
        
                return 0;
        }
        

        produces this quite clean pixmap:
        test.png

        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