QPrinter输出到pdf不等于纸张/页面尺寸(A4)

时间:2015-04-26 17:38:03

标签: c++ qt pdf qprinter

我正在尝试将QWidget ui输出到这样的pdf文件中;

const QString filename = "class1bills.pdf";

printer = new QPrinter(QPrinter::HighResolution);
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOrientation(QPrinter::Portrait);
printer->setPaperSize(QPrinter::A4);
printer->setPageSize(QPrinter::A4);
printer->setPageMargins (15,15,15,15,QPrinter::Millimeter);
printer->setFullPage(false);
printer->setOutputFileName(filename);

painter = new QPainter(printer);

class1Bill->render(painter, QPoint(), QRegion(), QWidget::DrawChildren | QWidget::DrawWindowBackground);

painter->begin(printer);
painter->end();

assert(QFile::exists(filename)); 

class1Bill是继承QWidget的类的对象。一切正常,但是当我打开pdf文件时,我希望小部件ui看起来符合A4页面大小,但它看起来非常小,我甚至没有看到它乍一看。如何使小部件ui适合我设置的A4纸张尺寸?

1 个答案:

答案 0 :(得分:0)

设置printer->setFullPage(true);以适合纸张尺寸