Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    7
    2594
    Loading More Posts
    • 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.
    • IMAN4K
      IMAN4K last edited by 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-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @IMAN4K last edited by 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.

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

        IMAN4K 1 Reply Last reply Reply Quote 0
        • IMAN4K
          IMAN4K @raven-worx last edited by 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-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @IMAN4K last edited by

            @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

            IMAN4K 1 Reply Last reply Reply Quote 0
            • IMAN4K
              IMAN4K @raven-worx last edited by

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

              raven-worx 1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators @IMAN4K last edited by

                @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 Reply Quote 0
                • IMAN4K
                  IMAN4K last edited by IMAN4K

                  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 Reply Quote 0
                  • First post
                    Last post