QPrinter orientation problem
-
I have to simulate a label printer (I don't have access to the printer right now), and QPrinter reverses the orientation.
I'm selecting printer by looping through printers in the system and selecting the printer that has the name I want to print to:
QString sPrinter = "PDFCreator"; QList<QPrinterInfo> printerList=QPrinterInfo::availablePrinters(); foreach (QPrinterInfo printerInfo, printerList) { if (printerInfo.printerName() == sPrinter) { ...
After finding my printer I check the width/height of the printer using:
QPageSize ps = printerInfo.defaultPageSize(); int width = ps.size(QPageSize::Millimeter).width(); int height = ps.size(QPageSize::Millimeter).height();
width is 80 mm, height is 800 mm
just as it set in windows.I then do:
QPrinter printer = new QPrinter(printerInfo, QPrinter::HighResolution); QPageLayout pla = printer->pageLayout(); int new_width = pla.fullRect(QPageLayout::Millimeter).width(); int new_height = pla.fullRect(QPageLayout::Millimeter).height();
However now new_width is 800 mm and new_height is 80 mm, that is the orientation has changed!
I need to know the paper width since I must support both label printer and A4 formats.
I tried printing to this printer from other applications (Chrome, Notepad, Windows printer test) and they give the right result.
Is this to be expected?? Or is this a bug??
QT opensource 6.4.2 Windows 10, MinGW. Printer is PDFCreator 5.0.3 by PDFforge. Setting in Windows Printing preferences, Advanced, Paper Size, Postscript Custom Page Size Definition, Width: 80mm, Height 800mm, this is to simulate a label printer.
-
I have to simulate a label printer (I don't have access to the printer right now), and QPrinter reverses the orientation.
I'm selecting printer by looping through printers in the system and selecting the printer that has the name I want to print to:
QString sPrinter = "PDFCreator"; QList<QPrinterInfo> printerList=QPrinterInfo::availablePrinters(); foreach (QPrinterInfo printerInfo, printerList) { if (printerInfo.printerName() == sPrinter) { ...
After finding my printer I check the width/height of the printer using:
QPageSize ps = printerInfo.defaultPageSize(); int width = ps.size(QPageSize::Millimeter).width(); int height = ps.size(QPageSize::Millimeter).height();
width is 80 mm, height is 800 mm
just as it set in windows.I then do:
QPrinter printer = new QPrinter(printerInfo, QPrinter::HighResolution); QPageLayout pla = printer->pageLayout(); int new_width = pla.fullRect(QPageLayout::Millimeter).width(); int new_height = pla.fullRect(QPageLayout::Millimeter).height();
However now new_width is 800 mm and new_height is 80 mm, that is the orientation has changed!
I need to know the paper width since I must support both label printer and A4 formats.
I tried printing to this printer from other applications (Chrome, Notepad, Windows printer test) and they give the right result.
Is this to be expected?? Or is this a bug??
QT opensource 6.4.2 Windows 10, MinGW. Printer is PDFCreator 5.0.3 by PDFforge. Setting in Windows Printing preferences, Advanced, Paper Size, Postscript Custom Page Size Definition, Width: 80mm, Height 800mm, this is to simulate a label printer.
-
@MartinGU
can you try to set this?
bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation)
https://doc.qt.io/qt-5.15/qprinter.html#setPageOrientation