我继承了一些 Netbeans QT C++ 代码,使用 QPrinters 的 PDF 打印效果很好,但打印到打印机只打印了一半的页面。代码相当简单。看起来有些东西正在页面上打印,但所有对象都被考虑(命名为每个对象)。
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);