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

Qt5 setPaperSize does not work on Macintosh

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.1.0
    • GUI: Printing
    • None
    • Mac
    • macOS

    Description

      A change made going from Qt4 to Qt5 broke the ability to preset a paper size in the print dialog.

      given

      QPrinter* printer = new QPrinter(QPrinter::HighResolution);
      printer->setPaperSize( QPrinter::Legal );
      m_printDialog = new QPrintDialog(printer);
      and then

      if( m_printDialog->exec()== QDialog::Accepted )

      { QPrinter *qprinter= m_printDialog->printer(); qDebug() << Q_FUNC_INFO << "after dialog, paper size now " << qprinter->paperSize(); }

      the page size in the dialog will not be preset to Legal.

      Reason this does not work in Qt5 is:
      In void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
      we have
      QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps);
      ...
      PMGetUnadjustedPaperRect(tmp, &paper);
      int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
      int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
      if (newSize.width() == wMM && newSize.height() == hMM) {
      but newSize is a QSizeF and float vs integer equality will (almost) never work.

      In Qt4 newSize is an integer
      QSize newSize = qt_paperSizeToQSizeF(ps).toSize();

      Reverting to Qt4's code is one option but it might be better to explicitly allow some slop in finding a paper size. Something like:
      if( absWidthDiff < 1.0 && absHeightDiff < 1.0 ) // 0.35mm is one Point so 1 mm should be enough.
      you could even use a loop with increasing slop values up to some limit.

      Affects all Qt5 versions as far as I can see.

      Attachments

        Issue Links

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

          Activity

            People

              johnlayt John Layt
              lazh Larry Hutchinson
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes