Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I'm sending out the pdf, but the resolution is low
Forum Updated to NodeBB v4.3 + New Features

I'm sending out the pdf, but the resolution is low

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 440 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meria0503
    wrote on last edited by
    #1

    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();
    }

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @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.

      M 2 Replies Last reply
      1
      • C ChrisW67

        @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.

        M Offline
        M Offline
        meria0503
        wrote on last edited by
        #3

        @ChrisW67 said in I'm sending out the pdf, but the resolution is low:

        Thank you for your advice! However, it is still difficult because the size of the output is still small.

        I don't know how to decide the size..

        1 Reply Last reply
        0
        • C ChrisW67

          @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.

          M Offline
          M Offline
          meria0503
          wrote on last edited by
          #4

          @ChrisW67

          It's not a 100% satisfactory result, but we still produced the desired result. Thank you.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved