Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.1.0
-
None
-
Mac
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
- is required for
-
QTBUG-25380 QtPrintSupport - Page Layout Issues
- Open
-
QTBUG-25383 QtPrintSupport - macOS Issues
- Closed