简体   繁体   中英

QT QPrinter printing partial page

I inherited some Netbeans QT C++ code and the PDF with QPrinters prints fine but printing to a printer only half the page prints. The code is fairly straight forward. It looks like something is printing over the page but all the objects are accounted for (named each object).

QPrinter * printer = new QPrinter(QPrinter::HighResolution);
QPainter painter;
painter.begin(printer);
double xscale = printer->pageRect().width()/double(width());
double yscale = printer->pageRect().height()/double(height());
double scale = qMin(xscale, yscale);
painter.translate(printer->paperRect().x() + printer->pageRect().width()/2,
                  printer->paperRect().y() + printer->pageRect().height()/2);
painter.scale(scale, scale);
painter.translate(-width()/2, -height()/2);

render(&painter);

To answer my own question is that QPrinter::HighResolution isn't working. If this problem occurs try QPrinter::ScreenResolution instead.

QPrinter(QPrinter::HighResolution);

You may want to detect if you are going to PDF instead of a printer and then change the printer resolution to at least 1200 dpi.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM