0

I have managed to generate bar-code on a QLabel. I have tried QPainter and I could not get properly aligned output. My label size is 50*25 mm for a label ,one row contain two label.

This is my code for printing label.

I want to know that, is there any solution to print label using html. So that I can design very well.

QPrinter printer1;
QList<QPrinterInfo> printerList = QPrinterInfo::availablePrinters() ;
for(int r=0; r<printerList.size();++r)
{
    if(printerList[r].printerName() == "TSC TE200")
    {
        QPageSize pageSize(QSizeF(45.0,70.0),QPageSize::Millimeter,"",QPageSize::ExactMatch);
        QPrinter PRINTER(printerList[r],QPrinter::PrinterResolution);
        PRINTER.setOrientation(QPrinter::Portrait);
        PRINTER.setPageSize(pageSize);
        PRINTER.setFullPage(true);
        PRINTER.setOutputFormat(QPrinter::NativeFormat);

       // int id = QFontDatabase::addApplicationFont("/Applications/untitledfolder/free3of9.ttf");
        // QFontDatabase::applicationFontFamilies(id).at(0);
        QFont barcodefont;
        barcodefont.setFamily("Code 128");
        barcodefont.setWeight(QFont::Normal);
        barcodefont.setPointSize(60);
        QFontMetrics fntm(barcodefont);

        QPainter painter2;
        if(!painter2.begin(&PRINTER))
                return;


        int x1 = printer1.paperRect().x() + printer1.width()/2 - 
        fntm.width("123456789")/2;enter code here
        int y1 = printer1.paperRect().y();
        int w1 = fntm.width("123456789");
        int h1 = fntm.height()/4;

        int x11 = printer1.paperRect().x() + printer1.width() - fntm.width("123456789")/2;
        int y11 = printer1.paperRect().y();
        int w11 = fntm.width("123456789");
        int h11 = fntm.height()/4;

        QRect rect10 = QRect(x1,y1,w1,h1);
        QRect rect20 = QRect(x11,y11,w11,h11);
        painter2.setFont(barcodefont);
        painter2.drawText(rect10,Qt::AlignLeft,"123456789");


        painter2.end();
        break;
        }
    } 

Sorry about my English. I'm not fluent in English.Thanks in advance.

m7913d
  • 10,244
  • 7
  • 28
  • 56
najeeb tp
  • 1
  • 2
  • Can you show an image of the result you get and indicate why is not the desired result? – m7913d Nov 25 '17 at 16:52
  • 1
    Possible duplicate of [How to generate barcode in qt?](https://stackoverflow.com/questions/39498215/how-to-generate-barcode-in-qt) – m7913d Nov 25 '17 at 16:55

0 Answers0