Getting the page sizes to UI: QPrinterInfo printer = QPrinterInfo::printerInfo() įor (auto x=0 xplistSizeBox->addItem(printer.supportedPageSizes().at(x). I removed all error checking and nonessential code. The UI had a combo box (named pListSizeBox) that had available paper sizes listed, user had to select the file, paper size (for many reasons this could not be the actual dimensions of the PDF file) and click on button.Īctual image was in a handy QImage named label. You want to print text, so instead of my drawImage() it would be drawText() for you (I find this part really tricky to implement as one needs to be careful about positioning the data for drawing - I printed mostly 4"圆" and 4"x2.5"). The case, as I mentioned, was different (I used Poppler library to render PDF files to bitmap, later on on Mac I switched to QtPDF but that is not relevant here). This code is ancient but the principles are there. When adjusting the left position, it is essential to note that label objects will stop at the 0 position, meaning they cant move any further to the left than the left edge of the label set by the printer. Left position: Used to move all objects to the left and the right. If your printer is not there it means the system can't see it properly and usual Qt routines will managed to find a copy of the routines I used years ago to deal with Zebra. Top position: Used to move all objects up or down on the label. Default and all page size are in the relevant QPrinterInfo object.īut first thing to try is to check if Qt sees your printer by checking return values from availablePrinterNames(). You also might need to setup page size before calling painter.begin() but I think default should work. QPrinter *printer = new QPrinter(printerInfo,QPrinter::HighResolution) QPrinterInfo printerInfo = QPrinterInfo::printerInfo(printers.at(0)) Code that should work: QStringList printers = QPrinterInfo::availablePrinterNames() Having checked that, let's assume that your printer is listed as the first one. You do QPrinterInfo::availablePrinterNames() (can be sent to qDebug()) - do you see the name of your Zebra? You should initialise the printer with exactly that name (I always copy it from relevant position in QStringList returned by availablePrinterNames()).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |