Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34276

Setting the paper size for QPrinter to a custom size has no effect on the final printed page size

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 4.8.4, 5.1.1
    • Fix Version/s: 5.2.0 RC1
    • Component/s: GUI: Printing
    • Labels:
      None
    • Environment:
      Windows, Linux
    • Commits:
      Manual test code: 2e8ad02b7d10c100dcd9d559b019c474fa4b8a29 (5.2 RC), Fix 3396ba5612c1047d1b21a90c4996dff848c00114

      Description

      The code below can be used to reproduce the issue:

      #include <QApplication>
      #include <QPrinter>
      #include <QPrintDialog>
      #include <QPainter>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QPrinter p;
          p.setPaperSize(QSizeF(5, 5), QPrinter::Inch);
          QPainter pp(&p);
          pp.drawRect(p.pageRect());
      
          QPrintDialog d(&p);
          qDebug() << p.printerName() << p.paperSize() << p.paperSize(QPrinter::Inch) << p.paperRect() << p.pageRect();
          if (d.exec()) {
              qDebug() << p.printerName() << p.paperSize() << p.paperSize(QPrinter::Inch) << p.paperRect() << p.pageRect();
              
          }
          return a.exec();
      }
      

      Expected result:
      The printed paperSize should be custom

      Actual result:
      The paperSize is set to A4

      The issue is present on Linux and Windows, but the outcome is different.

      on Linux:
      With the code above (printed to a file), the created pdf has the right size on Qt 4.8, but the dialog shows incorrect width and height. However, on Qt 5.x the created pdf has the width and height shown in the printdialog.

      on Windows:
      Both Qt 4.8 and Qt 5 the size is incorrect

      The patch attached should fix the issue on Windows for Qt 4.8.

        Attachments

        1. print_patch.diff
          1.0 kB
        2. qtbug34276.zip
          6 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              andysh Andy Shaw
              Reporter:
              qtcomsupport Qt Support
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes