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. Text is not good enough while using QPainter::drawText()?

Text is not good enough while using QPainter::drawText()?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 3.4k 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.
  • IMAN4KI Offline
    IMAN4KI Offline
    IMAN4K
    wrote on last edited by IMAN4K
    #1

    Hi.
    i'm trying to draw text using QPainter::drawText() but the text is not antialiased (comparing to MS word)

    void TextLabel::paintEvent(QPaintEvent*) {
        QPainter p(this);
        p.setRenderHint(QPainter::TextAntialiasing);
    
        QFont font;
        font.setFamily("Roboto medium");
        font.setPointSize(32);
        font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
    
        p.setPen(_brush);
        p.setFont(font);
    
        p.drawText(rect(), Qt::AlignLeft , _text);
    }
    

    Qt Doc says:

    QPainter::TextAntialiasing -> Indicates that the engine should antialias text if possible

    Is this impossible ?
    What should i do ?

    The word one : https://drive.google.com/file/d/0B-nmbIyXfagPNlBaaGRyWGhXM2s/view
    The Qt one : https://drive.google.com/file/d/0B-nmbIyXfagPR3FiLXd1ZkptREk/view

    raven-worxR 1 Reply Last reply
    0
    • IMAN4KI IMAN4K

      Hi.
      i'm trying to draw text using QPainter::drawText() but the text is not antialiased (comparing to MS word)

      void TextLabel::paintEvent(QPaintEvent*) {
          QPainter p(this);
          p.setRenderHint(QPainter::TextAntialiasing);
      
          QFont font;
          font.setFamily("Roboto medium");
          font.setPointSize(32);
          font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
      
          p.setPen(_brush);
          p.setFont(font);
      
          p.drawText(rect(), Qt::AlignLeft , _text);
      }
      

      Qt Doc says:

      QPainter::TextAntialiasing -> Indicates that the engine should antialias text if possible

      Is this impossible ?
      What should i do ?

      The word one : https://drive.google.com/file/d/0B-nmbIyXfagPNlBaaGRyWGhXM2s/view
      The Qt one : https://drive.google.com/file/d/0B-nmbIyXfagPR3FiLXd1ZkptREk/view

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @IMAN4K

      • which Qt version do you use?
      • did you compile Qt yourself?
      • which platform?

      i am not sure if it helps, but try to omit the Helvetica hint. And just set the stragedy:

      font.setStyleStrategy(QFont::PreferAntialias)
      

      But your text - in case you didn't downscale the posted images - is already anti-aliased. As you can see when you zoom into the image.
      I guess MS word and Qt are just using different anti-aliasing algorithms.

      --- 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

      IMAN4KI 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @IMAN4K

        • which Qt version do you use?
        • did you compile Qt yourself?
        • which platform?

        i am not sure if it helps, but try to omit the Helvetica hint. And just set the stragedy:

        font.setStyleStrategy(QFont::PreferAntialias)
        

        But your text - in case you didn't downscale the posted images - is already anti-aliased. As you can see when you zoom into the image.
        I guess MS word and Qt are just using different anti-aliasing algorithms.

        IMAN4KI Offline
        IMAN4KI Offline
        IMAN4K
        wrote on last edited by IMAN4K
        #3

        @raven-worx
        Using Qt5.5.1 on Windows.
        And no i didn't.

        That doesn't work too :(
        And yes they are not realy anti-aliased .

        raven-worxR 1 Reply Last reply
        0
        • IMAN4KI IMAN4K

          @raven-worx
          Using Qt5.5.1 on Windows.
          And no i didn't.

          That doesn't work too :(
          And yes they are not realy anti-aliased .

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @IMAN4K said:

          And yes they are realy anti-aliased .

          Then i am afraid there is not much you can do. Since Qt doesn't offer an such detailed anti-aliasing API.

          --- 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

          IMAN4KI 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @IMAN4K said:

            And yes they are realy anti-aliased .

            Then i am afraid there is not much you can do. Since Qt doesn't offer an such detailed anti-aliasing API.

            IMAN4KI Offline
            IMAN4KI Offline
            IMAN4K
            wrote on last edited by
            #5

            @raven-worx
            Ii means there is no way just for a simple text drawing ?

            raven-worxR 1 Reply Last reply
            0
            • IMAN4KI IMAN4K

              @raven-worx
              Ii means there is no way just for a simple text drawing ?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @IMAN4K
              as we already agreed anti-aliasing works.
              But not the way you would like it to. And the anti-aliasing algorithm can't be explicitly set AFAIK.

              --- 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
              • IMAN4KI Offline
                IMAN4KI Offline
                IMAN4K
                wrote on last edited by IMAN4K
                #7

                It seems Qt has issue on Window OS (font rendering) and work with some fonts >=48pt and doesn't work with some other.

                Issue : https://bugreports.qt.io/browse/QTBUG-40052

                We hope they will fix it in the near future.

                You can draw with QPainterPath it's more expensive but still helps :

                void TextLabel::paintEvent(QPaintEvent*) {
                	QPainter painter(this);
                	painter.setRenderHint(QPainter::Antialiasing);
                	painter.setBrush(Qt::black);
                
                	QFont font;
                	font.setPointSize(38);
                	font.setFamily("Roboto");
                
                	painter.setFont(font);
                
                	painter.drawText(0, 60, "Google");
                
                	QPainterPath textPath, path0;
                	textPath.addText(0, 140, font, "Google");
                	painter.drawPath(textPath);
                }
                

                Roboto @ 38pt :

                enter image description here

                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