I'm sending out the pdf, but the resolution is low
-
Hello, I'm a beginner at qt.
The question this time is to capture the screen and send out the pdf. Code implementation works well. However, there is a problem with the resolution adjustment and the output is too small. What's the problem?
Below is the code.
void Mainwindow::on_pushButton_Print_clicked()
{QString filePath = QFileDialog::getSaveFileName(this, QString(tr("Print as PDF...")), QString(), "PDF file (*.pdf)"); if(filePath.isEmpty()) return; QPrinter pdfPrinter(QPrinter::HighResolution); pdfPrinter.setOutputFormat(QPrinter::PdfFormat); pdfPrinter.setOutputFileName(filePath); pdfPrinter.setPageSize(QPageSize::A4); pdfPrinter.setResolution(600); QPainter painter; painter.begin(&pdfPrinter);
int maxheight = ui->centralwidget->maximumHeight();
int maxwidth = ui->centralwidget->maximumWidth();QString originalStyle = ui->centralwidget->styleSheet();
ui->centralwidget->setStyleSheet("background-color:white;");
ui->centralwidget->render(&painter);
ui->centralwidget->setStyleSheet(originalStyle);painter.translate(pdfPrinter.paperRect(QPrinter::Millimeter).center());
painter.scale(maxwidth,maxheight);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.end();
} -
@meria0503 said in I'm sending out the pdf, but the resolution is low:
painter.scale(maxwidth,maxheight);
QPainter::scale() takes X and Y scaling factors, i.e. 0.5 halves the size of anything drawn while 2.0 will double everything, not a final size in pixels which I think is what you are assuming here. In any case this occurs in your code after the screen content has been rendered.
At 600 DPI a 1920x1080 screen , for example, would be expected to span 3.2 inches.