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 Bold
QtWS25 Last Chance

QPainter drawtext Bold

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 4 Posters 10.9k 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.
  • T Offline
    T Offline
    TheCipo76
    wrote on 25 Jan 2019, 12:59 last edited by TheCipo76
    #1

    Hi,
    i'm creating a PDF with QPrinter and QPainter..

        qreal top=15, left=10, right=10, bottom=15;
        QPrinter printer(QPrinter::HighResolution);
        printer.setOrientation(QPrinter::Portrait);
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setPaperSize(QPrinter::A4);
        printer.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
        Oggi = QDate::currentDate();
        QString DtOggi = Oggi.toString("dd-MM-yyyy");
        ui->lineEdit_DtRNC->setText(DtOggi);
        QString NomeFile = "RNC " + ui->comboBox_Fornitore->currentText() + " del " + DtOggi;
        QString fileName = QFileDialog::getSaveFileName(nullptr,"file", NomeFile, "pdf (*.pdf)");
        printer.setOutputFileName(fileName);
        QPainter painter;
        painter.begin(&printer);
        QPen paintpen (Qt::black);
        painter.setPen(paintpen);
        painter.setFont(QFont("Verdana", 20, QFont::ExtraBold));
        painter.drawText(2000, 50, "BOLD TEXT");                                //BOLD TEXT
        painter.setFont(QFont("Verdana", 12, QFont::Normal));
        painter.drawText(2000, 250, "NORMAL TEXT");                      // NORMAL TEXT
    

    but when i open the PDF file all the text was normal.. Bold was not applied

    Anyone know why??
    Thanks in advance.

    J 1 Reply Last reply 25 Jan 2019, 13:43
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 25 Jan 2019, 13:35 last edited by
      #2

      Hi
      What platform ?

      T 1 Reply Last reply 25 Jan 2019, 13:37
      0
      • M mrjj
        25 Jan 2019, 13:35

        Hi
        What platform ?

        T Offline
        T Offline
        TheCipo76
        wrote on 25 Jan 2019, 13:37 last edited by
        #3

        @mrjj Mac OS X 10.14.3

        M 1 Reply Last reply 25 Jan 2019, 13:39
        0
        • T TheCipo76
          25 Jan 2019, 13:37

          @mrjj Mac OS X 10.14.3

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 25 Jan 2019, 13:39 last edited by
          #4

          @TheCipo76
          Ok, im asking as it seems just as odd as
          https://forum.qt.io/topic/98726/qtextedit-make-text-bold
          which is also mac.

          Could you also try with
          http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-example.html
          and use Verdana and see if that sample can make it bold ?

          T 1 Reply Last reply 25 Jan 2019, 14:12
          0
          • T TheCipo76
            25 Jan 2019, 12:59

            Hi,
            i'm creating a PDF with QPrinter and QPainter..

                qreal top=15, left=10, right=10, bottom=15;
                QPrinter printer(QPrinter::HighResolution);
                printer.setOrientation(QPrinter::Portrait);
                printer.setOutputFormat(QPrinter::PdfFormat);
                printer.setPaperSize(QPrinter::A4);
                printer.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
                Oggi = QDate::currentDate();
                QString DtOggi = Oggi.toString("dd-MM-yyyy");
                ui->lineEdit_DtRNC->setText(DtOggi);
                QString NomeFile = "RNC " + ui->comboBox_Fornitore->currentText() + " del " + DtOggi;
                QString fileName = QFileDialog::getSaveFileName(nullptr,"file", NomeFile, "pdf (*.pdf)");
                printer.setOutputFileName(fileName);
                QPainter painter;
                painter.begin(&printer);
                QPen paintpen (Qt::black);
                painter.setPen(paintpen);
                painter.setFont(QFont("Verdana", 20, QFont::ExtraBold));
                painter.drawText(2000, 50, "BOLD TEXT");                                //BOLD TEXT
                painter.setFont(QFont("Verdana", 12, QFont::Normal));
                painter.drawText(2000, 250, "NORMAL TEXT");                      // NORMAL TEXT
            

            but when i open the PDF file all the text was normal.. Bold was not applied

            Anyone know why??
            Thanks in advance.

            J Offline
            J Offline
            JonB
            wrote on 25 Jan 2019, 13:43 last edited by
            #5

            @TheCipo76 , @mrjj
            Hmm, is it simple coincidence that the on-going https://forum.qt.io/topic/98726/qtextedit-make-text-bold seems unresolved and is reporting a similar problem with no-bold, though admittedly in a QTextEdit. Any connection...??

            M 1 Reply Last reply 25 Jan 2019, 13:47
            1
            • J JonB
              25 Jan 2019, 13:43

              @TheCipo76 , @mrjj
              Hmm, is it simple coincidence that the on-going https://forum.qt.io/topic/98726/qtextedit-make-text-bold seems unresolved and is reporting a similar problem with no-bold, though admittedly in a QTextEdit. Any connection...??

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 25 Jan 2019, 13:47 last edited by mrjj
              #6

              @JonB
              Yes, same code works on other platforms.
              And if sample dont work either, its an OS/Qt thing. (it seems as no Qt app can make font bold then)
              But yes could also be totally a coincidence but i have no macOS to test on.

              1 Reply Last reply
              0
              • M mrjj
                25 Jan 2019, 13:39

                @TheCipo76
                Ok, im asking as it seems just as odd as
                https://forum.qt.io/topic/98726/qtextedit-make-text-bold
                which is also mac.

                Could you also try with
                http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-example.html
                and use Verdana and see if that sample can make it bold ?

                T Offline
                T Offline
                TheCipo76
                wrote on 25 Jan 2019, 14:12 last edited by TheCipo76
                #7

                @mrjj Yes, i've tried using Verdana and works correctly

                I've modified my code like this:

                QFont bold("Verdana", 20);
                bold.setBold(true);
                painter.setFont(bold);
                painter.drawText(2000, 50, "BOLD TEXT");
                

                but no bold text..

                M T 2 Replies Last reply 25 Jan 2019, 14:48
                0
                • T TheCipo76
                  25 Jan 2019, 14:12

                  @mrjj Yes, i've tried using Verdana and works correctly

                  I've modified my code like this:

                  QFont bold("Verdana", 20);
                  bold.setBold(true);
                  painter.setFont(bold);
                  painter.drawText(2000, 50, "BOLD TEXT");
                  

                  but no bold text..

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 25 Jan 2019, 14:48 last edited by mrjj
                  #8

                  @TheCipo76
                  Hi
                  Tried your code.
                  The QPainter was not active. ( logged errors to Creator)
                  QPainter::begin(): Returned false
                  QPainter::begin(): Returned false
                  QPainter::setPen: Painter not active
                  QPainter::setFont: Painter not active
                  QPainter::setFont: Painter not active
                  so font was never set, i think.
                  if i do

                  ....
                        QPainter painter(&printer); // give it directly
                         //painter.begin(&printer);
                         QPen paintpen (Qt::black);
                         painter.setPen(paintpen);
                  ...
                  

                  i get
                  alt text

                  T 1 Reply Last reply 25 Jan 2019, 16:02
                  2
                  • M mrjj
                    25 Jan 2019, 14:48

                    @TheCipo76
                    Hi
                    Tried your code.
                    The QPainter was not active. ( logged errors to Creator)
                    QPainter::begin(): Returned false
                    QPainter::begin(): Returned false
                    QPainter::setPen: Painter not active
                    QPainter::setFont: Painter not active
                    QPainter::setFont: Painter not active
                    so font was never set, i think.
                    if i do

                    ....
                          QPainter painter(&printer); // give it directly
                           //painter.begin(&printer);
                           QPen paintpen (Qt::black);
                           painter.setPen(paintpen);
                    ...
                    

                    i get
                    alt text

                    T Offline
                    T Offline
                    TheCipo76
                    wrote on 25 Jan 2019, 16:02 last edited by TheCipo76
                    #9

                    @mrjj i've made the changes you told me up but
                    nothing changed
                    no way to have bold text

                    with qdebug i've checked font selection
                    this is debug message

                    Painter isActive: true
                    Painter Font: QFont( "Verdana,20,-1,5,75,0,0,0,0,0" ) //Bold
                    Painter Font: QFont( "Verdana,12,-1,5,50,0,0,0,0,0" )
                    Painter Font: QFont( "Verdana,10,-1,5,50,0,0,0,0,0" )
                    Painter Font: QFont( "Verdana,12,-1,5,75,0,0,0,0,0" ) //Bold
                    Painter Font: QFont( "Verdana,11,-1,5,75,0,0,0,0,0" ) //Bold
                    Painter Font: QFont( "Verdana,11,-1,5,50,0,0,0,0,0" )
                    Painter Font: QFont( "Verdana,11,-1,5,75,0,0,0,0,0" ) //Bold
                    Painter Font: QFont( "Verdana,11,-1,5,50,0,0,0,0,0" )

                    75 is Bold ( as i've setted by code..)

                    but was not applied

                    Probably was a bug

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 26 Jan 2019, 10:50 last edited by mrjj
                      #10

                      Hi
                      Could you try test app ?
                      https://www.dropbox.com/s/eftitvdqvw60otr/boldfont.zip?dl=0

                      I wanna know if you get bold on image and please also try to pdf and tell
                      if font still not bold there.

                      alt text

                      T 1 Reply Last reply 26 Jan 2019, 11:05
                      0
                      • M mrjj
                        26 Jan 2019, 10:50

                        Hi
                        Could you try test app ?
                        https://www.dropbox.com/s/eftitvdqvw60otr/boldfont.zip?dl=0

                        I wanna know if you get bold on image and please also try to pdf and tell
                        if font still not bold there.

                        alt text

                        T Offline
                        T Offline
                        TheCipo76
                        wrote on 26 Jan 2019, 11:05 last edited by
                        #11

                        @mrjj Yes, i've tried it and works great both pdf than image!

                        M 1 Reply Last reply 26 Jan 2019, 11:12
                        0
                        • T TheCipo76
                          26 Jan 2019, 11:05

                          @mrjj Yes, i've tried it and works great both pdf than image!

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 26 Jan 2019, 11:12 last edited by
                          #12

                          @TheCipo76
                          Oh so PDF also worked with this sample ?

                          T 1 Reply Last reply 26 Jan 2019, 11:15
                          0
                          • M mrjj
                            26 Jan 2019, 11:12

                            @TheCipo76
                            Oh so PDF also worked with this sample ?

                            T Offline
                            T Offline
                            TheCipo76
                            wrote on 26 Jan 2019, 11:15 last edited by TheCipo76
                            #13

                            @mrjj Yes..
                            i don't know why (it was my code... or not??)

                            M 1 Reply Last reply 26 Jan 2019, 11:19
                            0
                            • T TheCipo76
                              26 Jan 2019, 11:15

                              @mrjj Yes..
                              i don't know why (it was my code... or not??)

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 26 Jan 2019, 11:19 last edited by mrjj
                              #14

                              @TheCipo76
                              Sample is like 98% your code. just removed the Date stuff.
                              Even to Image is your code, just to a pixmap.
                              Rest of it, is the same. So something must have went wrong
                              altering the code, or maybe it didnt use new code or something.

                              T 1 Reply Last reply 26 Jan 2019, 11:23
                              0
                              • M mrjj
                                26 Jan 2019, 11:19

                                @TheCipo76
                                Sample is like 98% your code. just removed the Date stuff.
                                Even to Image is your code, just to a pixmap.
                                Rest of it, is the same. So something must have went wrong
                                altering the code, or maybe it didnt use new code or something.

                                T Offline
                                T Offline
                                TheCipo76
                                wrote on 26 Jan 2019, 11:23 last edited by
                                #15

                                @mrjj ok, now i will search where is the problem..

                                M 1 Reply Last reply 26 Jan 2019, 11:29
                                0
                                • T TheCipo76
                                  26 Jan 2019, 11:23

                                  @mrjj ok, now i will search where is the problem..

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 26 Jan 2019, 11:29 last edited by mrjj
                                  #16

                                  @TheCipo76
                                  Good hunting. Now we know it will work so
                                  its just to compare sample to actual code and see what could be difference.

                                  T 1 Reply Last reply 26 Jan 2019, 12:49
                                  0
                                  • M mrjj
                                    26 Jan 2019, 11:29

                                    @TheCipo76
                                    Good hunting. Now we know it will work so
                                    its just to compare sample to actual code and see what could be difference.

                                    T Offline
                                    T Offline
                                    TheCipo76
                                    wrote on 26 Jan 2019, 12:49 last edited by
                                    #17

                                    @mrjj Thank you.. it's what i will do ;)

                                    M 1 Reply Last reply 26 Jan 2019, 12:52
                                    0
                                    • T TheCipo76
                                      26 Jan 2019, 12:49

                                      @mrjj Thank you.. it's what i will do ;)

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 26 Jan 2019, 12:52 last edited by
                                      #18

                                      @TheCipo76
                                      When you find it, please tell here.
                                      Its always good for me to know what i missed.

                                      T 1 Reply Last reply 26 Jan 2019, 18:57
                                      0
                                      • M mrjj
                                        26 Jan 2019, 12:52

                                        @TheCipo76
                                        When you find it, please tell here.
                                        Its always good for me to know what i missed.

                                        T Offline
                                        T Offline
                                        TheCipo76
                                        wrote on 26 Jan 2019, 18:57 last edited by
                                        #19

                                        @mrjj Sorry .. my bad..
                                        when you asked to try app i was working on windows..
                                        on mac don't works in image and neither pdf

                                        M 1 Reply Last reply 26 Jan 2019, 19:01
                                        0
                                        • T TheCipo76
                                          26 Jan 2019, 18:57

                                          @mrjj Sorry .. my bad..
                                          when you asked to try app i was working on windows..
                                          on mac don't works in image and neither pdf

                                          M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 26 Jan 2019, 19:01 last edited by
                                          #20

                                          @TheCipo76
                                          Aha, and did you try the
                                          http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-example.html
                                          example on mac too ?
                                          We have other poster that has Bold issue on macOs.
                                          https://forum.qt.io/topic/98726/qtextedit-make-text-bold

                                          so its kinda important to know if RichText sample do not go bold for you either as it then
                                          smells like a Qt thing /Xcode / macOS version thing.

                                          T 1 Reply Last reply 26 Jan 2019, 19:04
                                          0

                                          7/37

                                          25 Jan 2019, 14:12

                                          topic:navigator.unread, 30
                                          • Login

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