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

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.2.0 RC1
    • 4.8.4, 5.1.1
    • GUI: Printing
    • None
    • Windows, Linux
    • 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
          Qt Support
        2. qtbug34276.zip
          6 kB
          Friedemann Kleint

        Issue Links

          For Gerrit Dashboard: QTBUG-34276
          # Subject Branch Project Status CR V

          Activity

            People

              andysh Andy Shaw
              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