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

QPrinter with custom margins fails to properly render QGraphicsScene on Mac

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • 4.8.x
    • 4.7.4
    • GUI: Printing
    • None
    • Mac 10.6.8
    • macOS

    Description

      When you try to render a QGraphicsScene to a QPainter operating on a QPrinter, the calculated target page size is incorrect.

      The application below should display the scene within the printed page. (It works on Windows and X11.) On the Mac, the rectangle goes off the page to the right and bottom. Poking around, it looks like the device width and height are not being set correctly, so the default target page rect is wrong.

      main.cpp
      #include <QtGui>
      
      int main(int argc, char ** argv) {
        QApplication app(argc, argv);
      
        QGraphicsScene scene;
        scene.addRect(0., 0., 110., 197., QPen(), QBrush(Qt::BDiagPattern));
      
        QGraphicsView view(&scene);
        view.show();
      
        QPrinter printer(QPrinter::HighResolution);
        printer.setPaperSize(QPrinter::A4);
        printer.setPageMargins(50., 50., 50., 50., QPrinter::Millimeter);
      
        QPrintDialog dialog(&printer, &view);
        if (dialog.exec() == QDialog::Accepted) {
          QPainter painter(&printer);
          scene.render(&painter);
        }
      
        return app.exec();
      }
      

      Attachments

        Issue Links

          Activity

            People

              johnlayt John Layt
              dmateer Dave Mateer
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: