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. Blurry and strange color when creating barcode using fonts
QtWS25 Last Chance

Blurry and strange color when creating barcode using fonts

Scheduled Pinned Locked Moved Solved General and Desktop
barcodeqimagefontqt5.15.2
13 Posts 3 Posters 1.8k 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on 10 Sept 2021, 09:01 last edited by Proton Phoenix 9 Oct 2021, 09:02
    #1

    Hi ~~~~
    I have a problem with Creating Barcodes using fonts ~~
    barcode Label Size should be (50,25)
    or (100,40)
    the problem is when writing at higher size of barcode font , it works without any color or blurry problem
    but at small font size it shows strange green or multiple color on the barcode ,
    scan works smoothly without any problem even with those strange colors
    is there any solution?
    i have used an external library but it could create just QR CODE which is a problem on small labels

    blurry barcode font
    alt text
    i tried many fonts all have the same problem
    is that normal??

    A 1 Reply Last reply 10 Sept 2021, 09:12
    0
    • P Proton Phoenix
      10 Sept 2021, 09:36

      @mrjj Windows 10 and with latest updates

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Sept 2021, 09:44 last edited by
      #6

      @Proton-Phoenix
      Ok for test, you could try disable it and see if it has any effect.
      https://www.tenforums.com/tutorials/126775-enable-disable-font-smoothing-windows.html

      P 1 Reply Last reply 10 Sept 2021, 09:55
      3
      • P Proton Phoenix
        10 Sept 2021, 09:01

        Hi ~~~~
        I have a problem with Creating Barcodes using fonts ~~
        barcode Label Size should be (50,25)
        or (100,40)
        the problem is when writing at higher size of barcode font , it works without any color or blurry problem
        but at small font size it shows strange green or multiple color on the barcode ,
        scan works smoothly without any problem even with those strange colors
        is there any solution?
        i have used an external library but it could create just QR CODE which is a problem on small labels

        blurry barcode font
        alt text
        i tried many fonts all have the same problem
        is that normal??

        A Offline
        A Offline
        artwaw
        wrote on 10 Sept 2021, 09:12 last edited by
        #2

        @Proton-Phoenix Please show the code when you render the labels. I've been through the hoops with Code-39 labels printed on Zebra hardware.

        For more information please re-read.

        Kind Regards,
        Artur

        P 1 Reply Last reply 10 Sept 2021, 09:32
        2
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 10 Sept 2021, 09:31 last edited by
          #3

          Hi

          Is that not just normal font antialiasing?
          What platform is this ?

          P 1 Reply Last reply 10 Sept 2021, 09:36
          1
          • A artwaw
            10 Sept 2021, 09:12

            @Proton-Phoenix Please show the code when you render the labels. I've been through the hoops with Code-39 labels printed on Zebra hardware.

            P Offline
            P Offline
            Proton Phoenix
            wrote on 10 Sept 2021, 09:32 last edited by Proton Phoenix 9 Oct 2021, 09:34
            #4

            Hi Bro this is my code
            i have tried anti aliasing .... nothing changed the same problem

            int width = 300;
                int height = 120;
                 QImage image = QPixmap(width, height).toImage();
            
            QPainter painter(&image);
            painter.setRenderHints(QPainter::SmoothPixmapTransform,true);
            
            
            
               image.fill(Qt::white);
               painter.setPen(Qt::black);
            
            if(ui->barcodelineedit->text().length()<12){
                    painter.setFont(QFont("IDAutomationHC39M Free Version", 12));
                    painter.drawText(QPoint(90,105), ui->barcodelineedit->text());
            
                }else{
                    painter.setFont(QFont("IDAutomationHC39M Free Version", 12));
                    painter.drawText(QPoint(40,105), ui->barcodelineedit->text());
                }
            
                ui->showiteminfolabel->setPixmap(QPixmap::fromImage(image));
            
            A 1 Reply Last reply 10 Sept 2021, 09:56
            0
            • M mrjj
              10 Sept 2021, 09:31

              Hi

              Is that not just normal font antialiasing?
              What platform is this ?

              P Offline
              P Offline
              Proton Phoenix
              wrote on 10 Sept 2021, 09:36 last edited by Proton Phoenix 9 Oct 2021, 09:39
              #5

              @mrjj Windows 10 and with latest updates

              M 1 Reply Last reply 10 Sept 2021, 09:44
              0
              • P Proton Phoenix
                10 Sept 2021, 09:36

                @mrjj Windows 10 and with latest updates

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 10 Sept 2021, 09:44 last edited by
                #6

                @Proton-Phoenix
                Ok for test, you could try disable it and see if it has any effect.
                https://www.tenforums.com/tutorials/126775-enable-disable-font-smoothing-windows.html

                P 1 Reply Last reply 10 Sept 2021, 09:55
                3
                • M mrjj
                  10 Sept 2021, 09:44

                  @Proton-Phoenix
                  Ok for test, you could try disable it and see if it has any effect.
                  https://www.tenforums.com/tutorials/126775-enable-disable-font-smoothing-windows.html

                  P Offline
                  P Offline
                  Proton Phoenix
                  wrote on 10 Sept 2021, 09:55 last edited by
                  #7

                  @mrjj said in Blurry and strange color when creating barcode using fonts:

                  @Proton-Phoenix
                  Ok for test, you could try disable it and see if it has any effect.
                  https://www.tenforums.com/tutorials/126775-enable-disable-font-smoothing-windows.html

                  after disabling smooth edges and screen fonts
                  problem solved !!
                  but the normal texts ... on the label became so bad ~~~
                  now i understand it's not a font or QT problem
                  it's just the way windows render texts and images ...
                  so it's normal to see some green or other colors on the barcode

                  Really Thank you You always Save my day <3
                  i hope great happy life for all of you guys
                  many thanks again and again <3

                  1 Reply Last reply
                  0
                  • P Proton Phoenix
                    10 Sept 2021, 09:32

                    Hi Bro this is my code
                    i have tried anti aliasing .... nothing changed the same problem

                    int width = 300;
                        int height = 120;
                         QImage image = QPixmap(width, height).toImage();
                    
                    QPainter painter(&image);
                    painter.setRenderHints(QPainter::SmoothPixmapTransform,true);
                    
                    
                    
                       image.fill(Qt::white);
                       painter.setPen(Qt::black);
                    
                    if(ui->barcodelineedit->text().length()<12){
                            painter.setFont(QFont("IDAutomationHC39M Free Version", 12));
                            painter.drawText(QPoint(90,105), ui->barcodelineedit->text());
                    
                        }else{
                            painter.setFont(QFont("IDAutomationHC39M Free Version", 12));
                            painter.drawText(QPoint(40,105), ui->barcodelineedit->text());
                        }
                    
                        ui->showiteminfolabel->setPixmap(QPixmap::fromImage(image));
                    
                    A Offline
                    A Offline
                    artwaw
                    wrote on 10 Sept 2021, 09:56 last edited by artwaw 9 Oct 2021, 09:56
                    #8

                    @Proton-Phoenix Two questions:

                    • are you going to print them out or are they intended just for the on-screen use? If the latter there might be a limit related to the display. One work-around you can try is to print them much larger (font size 48 i.e.) and then scale down with Qt::KeepAspectRatio and Qt::SmoothTransformation. If the former - test on the printouts only, use either native dpi for the printer set explicitly (windows sometimes can't be trusted to get that right) or 300 (from my experience more doesn't make sense and eats lots of memory)
                    • are you certain that this font is at all able to produce crisp, small sized barcodes?

                    Me myself used to create barcodes for printing, like I mentioned, and getting anything to be read by a scanner with a small font failed until I used this font: https://www.dafont.com/c39hrp48dhtt.font

                    EDIT: I see problem is solved after I posted :)

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    P 1 Reply Last reply 10 Sept 2021, 10:05
                    2
                    • A artwaw
                      10 Sept 2021, 09:56

                      @Proton-Phoenix Two questions:

                      • are you going to print them out or are they intended just for the on-screen use? If the latter there might be a limit related to the display. One work-around you can try is to print them much larger (font size 48 i.e.) and then scale down with Qt::KeepAspectRatio and Qt::SmoothTransformation. If the former - test on the printouts only, use either native dpi for the printer set explicitly (windows sometimes can't be trusted to get that right) or 300 (from my experience more doesn't make sense and eats lots of memory)
                      • are you certain that this font is at all able to produce crisp, small sized barcodes?

                      Me myself used to create barcodes for printing, like I mentioned, and getting anything to be read by a scanner with a small font failed until I used this font: https://www.dafont.com/c39hrp48dhtt.font

                      EDIT: I see problem is solved after I posted :)

                      P Offline
                      P Offline
                      Proton Phoenix
                      wrote on 10 Sept 2021, 10:05 last edited by Proton Phoenix 9 Oct 2021, 10:10
                      #9

                      @artwaw said in Blurry and strange color when creating barcode using fonts:

                      @Proton-Phoenix Two questions:

                      • are you going to print them out or are they intended just for the on-screen use? If the latter there might be a limit related to the display. One work-around you can try is to print them much larger (font size 48 i.e.) and then scale down with Qt::KeepAspectRatio and Qt::SmoothTransformation. If the former - test on the printouts only, use either native dpi for the printer set explicitly (windows sometimes can't be trusted to get that right) or 300 (from my experience more doesn't make sense and eats lots of memory)
                      • are you certain that this font is at all able to produce crisp, small sized barcodes?

                      Me myself used to create barcodes for printing, like I mentioned, and getting anything to be read by a scanner with a small font failed until I used this font: https://www.dafont.com/c39hrp48dhtt.font

                      EDIT: I see problem is solved after I posted :)


                      really thank you bro too .. you helped me so many times before i will never forget that and you helped me so much here too
                      the label in the software it's just to show a preview to the user before printing the barcode label ....
                      i don't have barcode printer yet ... just testing
                      so it would be better to create bigger image with bigger fonts and then scale it down to barcode label size?
                      ok i will try that
                      i tried even

                      painter.setFont(QFont("IDAutomationHC39M Free Version", 10));

                      it just need barcode with a two stars or (barcode) ... as starting and ending point
                      and i am using my android smartphone to scan the output barcode .. even the small barcode and it can scan it fast without any problem
                      and i send it to my software tcp server ..

                      A 1 Reply Last reply 10 Sept 2021, 10:07
                      0
                      • P Proton Phoenix
                        10 Sept 2021, 10:05

                        @artwaw said in Blurry and strange color when creating barcode using fonts:

                        @Proton-Phoenix Two questions:

                        • are you going to print them out or are they intended just for the on-screen use? If the latter there might be a limit related to the display. One work-around you can try is to print them much larger (font size 48 i.e.) and then scale down with Qt::KeepAspectRatio and Qt::SmoothTransformation. If the former - test on the printouts only, use either native dpi for the printer set explicitly (windows sometimes can't be trusted to get that right) or 300 (from my experience more doesn't make sense and eats lots of memory)
                        • are you certain that this font is at all able to produce crisp, small sized barcodes?

                        Me myself used to create barcodes for printing, like I mentioned, and getting anything to be read by a scanner with a small font failed until I used this font: https://www.dafont.com/c39hrp48dhtt.font

                        EDIT: I see problem is solved after I posted :)


                        really thank you bro too .. you helped me so many times before i will never forget that and you helped me so much here too
                        the label in the software it's just to show a preview to the user before printing the barcode label ....
                        i don't have barcode printer yet ... just testing
                        so it would be better to create bigger image with bigger fonts and then scale it down to barcode label size?
                        ok i will try that
                        i tried even

                        painter.setFont(QFont("IDAutomationHC39M Free Version", 10));

                        it just need barcode with a two stars or (barcode) ... as starting and ending point
                        and i am using my android smartphone to scan the output barcode .. even the small barcode and it can scan it fast without any problem
                        and i send it to my software tcp server ..

                        A Offline
                        A Offline
                        artwaw
                        wrote on 10 Sept 2021, 10:07 last edited by
                        #10

                        @Proton-Phoenix it all depends on the use case BUT if the target use is on paper, render for that. Then for the preview just scale down.

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        P 1 Reply Last reply 10 Sept 2021, 10:12
                        1
                        • A artwaw
                          10 Sept 2021, 10:07

                          @Proton-Phoenix it all depends on the use case BUT if the target use is on paper, render for that. Then for the preview just scale down.

                          P Offline
                          P Offline
                          Proton Phoenix
                          wrote on 10 Sept 2021, 10:12 last edited by Proton Phoenix 9 Oct 2021, 10:14
                          #11

                          @artwaw said in Blurry and strange color when creating barcode using fonts:

                          @Proton-Phoenix it all depends on the use case BUT if the target use is on paper, render for that. Then for the preview just scale down.

                          the main purpose for me is to print it on a paper .. but i don't have it yet
                          that's why i am using small size QImage like QSizeF(100,40)
                          i am thinking that if i create bigger images it can't be printing as page on the Barcode printer .. so i must have one to test on real better than imagination ...
                          but
                          really thank you bro for all this great support <3

                          i hope you try the font that i am using now and tell me your opinion if it works with you on small sized barcode
                          ...
                          i hope great happy life for you <3

                          A 1 Reply Last reply 10 Sept 2021, 10:23
                          0
                          • P Proton Phoenix
                            10 Sept 2021, 10:12

                            @artwaw said in Blurry and strange color when creating barcode using fonts:

                            @Proton-Phoenix it all depends on the use case BUT if the target use is on paper, render for that. Then for the preview just scale down.

                            the main purpose for me is to print it on a paper .. but i don't have it yet
                            that's why i am using small size QImage like QSizeF(100,40)
                            i am thinking that if i create bigger images it can't be printing as page on the Barcode printer .. so i must have one to test on real better than imagination ...
                            but
                            really thank you bro for all this great support <3

                            i hope you try the font that i am using now and tell me your opinion if it works with you on small sized barcode
                            ...
                            i hope great happy life for you <3

                            A Offline
                            A Offline
                            artwaw
                            wrote on 10 Sept 2021, 10:23 last edited by
                            #12

                            @Proton-Phoenix I no longer have access to the Zebra I was using in the past (I changed the company since then).
                            Zebra printers are a story on their own to troubleshoot anyway...

                            General approach I used:

                            • make sure the printer is configured properly in the system, with the default page size set to the target page size.
                            • query the QPrinterInfo instance for the default page size.
                            • use that data with QPdfWriter to render whatever text + barcode I need.
                            • remember DPI settings, either set what the manual for the printer says (ideal) or 300 (this didn't end well for Dymo printers I used for a while, needed exact DPI of 204 ;) ).
                            • print and enjoy.

                            In general getting this to work might be lots of trial and error, depending on the brand and drivers. But once it's done right it is literally zero maintenance for years.

                            For more information please re-read.

                            Kind Regards,
                            Artur

                            P 1 Reply Last reply 10 Sept 2021, 10:49
                            4
                            • A artwaw
                              10 Sept 2021, 10:23

                              @Proton-Phoenix I no longer have access to the Zebra I was using in the past (I changed the company since then).
                              Zebra printers are a story on their own to troubleshoot anyway...

                              General approach I used:

                              • make sure the printer is configured properly in the system, with the default page size set to the target page size.
                              • query the QPrinterInfo instance for the default page size.
                              • use that data with QPdfWriter to render whatever text + barcode I need.
                              • remember DPI settings, either set what the manual for the printer says (ideal) or 300 (this didn't end well for Dymo printers I used for a while, needed exact DPI of 204 ;) ).
                              • print and enjoy.

                              In general getting this to work might be lots of trial and error, depending on the brand and drivers. But once it's done right it is literally zero maintenance for years.

                              P Offline
                              P Offline
                              Proton Phoenix
                              wrote on 10 Sept 2021, 10:49 last edited by
                              #13

                              @artwaw said in Blurry and strange color when creating barcode using fonts:

                              @Proton-Phoenix I no longer have access to the Zebra I was using in the past (I changed the company since then).
                              Zebra printers are a story on their own to troubleshoot anyway...

                              General approach I used:

                              • make sure the printer is configured properly in the system, with the default page size set to the target page size.
                              • query the QPrinterInfo instance for the default page size.
                              • use that data with QPdfWriter to render whatever text + barcode I need.
                              • remember DPI settings, either set what the manual for the printer says (ideal) or 300 (this didn't end well for Dymo printers I used for a while, needed exact DPI of 204 ;) ).
                              • print and enjoy.

                              In general getting this to work might be lots of trial and error, depending on the brand and drivers. But once it's done right it is literally zero maintenance for years.

                              <3 Thank you bro for everything <3

                              1 Reply Last reply
                              0

                              1/13

                              10 Sept 2021, 09:01

                              • Login

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