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

Custom paper size causes QGraphicsScene::render to misbehave 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 set a custom paper size on the Mac, a scene rendered to the printer only appears in a small portion of the page in the upper-left. The reason is that the default target rect is being set incorrectly within QGraphicsScene::render, obtaining a faulty value from QMacPrintEngine::metric().

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

      This is related to, but not the same as, QTBUG-18723. The fix is similar. I think I have it fixed, and will submit a patch for review after some more testing.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dmateer Dave Mateer
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: