简体   繁体   English

QT QPrinter打印部分页面

[英]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. 我继承了一些Netbeans QT C ++代码,带有QPrinters的PDF可以很好地打印,但是在打印机上只打印一半的页面打印。 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. 要回答我自己的问题,是QPrinter :: HighResolution无法正常工作。 If this problem occurs try QPrinter::ScreenResolution instead. 如果发生此问题,请尝试使用QPrinter :: ScreenResolution。

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. 您可能需要检测是否要转为PDF而不是打印机,然后将打印机分辨率更改为至少1200 dpi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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