我正在尝试将 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 纸张尺寸?