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
Forum Updated to NodeBB v4.3 + New Features

QPainter drawtext Bold

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 4 Posters 11.6k Views 1 Watching
  • 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.
  • TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What platform ?

      TheCipo76T 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        What platform ?

        TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by
        #3

        @mrjj Mac OS X 10.14.3

        mrjjM 1 Reply Last reply
        0
        • TheCipo76T TheCipo76

          @mrjj Mac OS X 10.14.3

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 ?

          TheCipo76T 1 Reply Last reply
          0
          • TheCipo76T TheCipo76

            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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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...??

            mrjjM 1 Reply Last reply
            1
            • JonBJ JonB

              @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...??

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              • mrjjM mrjj

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

                TheCipo76T Offline
                TheCipo76T Offline
                TheCipo76
                wrote on 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..

                mrjjM TheCipo76T 2 Replies Last reply
                0
                • TheCipo76T TheCipo76

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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

                  TheCipo76T 1 Reply Last reply
                  2
                  • mrjjM mrjj

                    @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

                    TheCipo76T Offline
                    TheCipo76T Offline
                    TheCipo76
                    wrote on 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
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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

                      TheCipo76T 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        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

                        TheCipo76T Offline
                        TheCipo76T Offline
                        TheCipo76
                        wrote on last edited by
                        #11

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

                        mrjjM 1 Reply Last reply
                        0
                        • TheCipo76T TheCipo76

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

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @TheCipo76
                          Oh so PDF also worked with this sample ?

                          TheCipo76T 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @TheCipo76
                            Oh so PDF also worked with this sample ?

                            TheCipo76T Offline
                            TheCipo76T Offline
                            TheCipo76
                            wrote on last edited by TheCipo76
                            #13

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

                            mrjjM 1 Reply Last reply
                            0
                            • TheCipo76T TheCipo76

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

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 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.

                              TheCipo76T 1 Reply Last reply
                              0
                              • mrjjM mrjj

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

                                TheCipo76T Offline
                                TheCipo76T Offline
                                TheCipo76
                                wrote on last edited by
                                #15

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

                                mrjjM 1 Reply Last reply
                                0
                                • TheCipo76T TheCipo76

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

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 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.

                                  TheCipo76T 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

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

                                    TheCipo76T Offline
                                    TheCipo76T Offline
                                    TheCipo76
                                    wrote on last edited by
                                    #17

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

                                    mrjjM 1 Reply Last reply
                                    0
                                    • TheCipo76T TheCipo76

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

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

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

                                      TheCipo76T 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

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

                                        TheCipo76T Offline
                                        TheCipo76T Offline
                                        TheCipo76
                                        wrote on 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

                                        mrjjM 1 Reply Last reply
                                        0
                                        • TheCipo76T TheCipo76

                                          @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

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 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.

                                          TheCipo76T 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