summaryrefslogtreecommitdiffstats
path: root/src/printsupport/dialogs/qprintdialog_mac.mm
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-06-16 16:05:17 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-06-17 19:06:10 +0200
commitb2fb14b7ba1db35eebf7621ead12909b35ec4042 (patch)
tree2bca6d4c72e2651805e07d9c3fe94203a4971762 /src/printsupport/dialogs/qprintdialog_mac.mm
parent29176bf2f836ba05206680ae1c00edf786202648 (diff)
macOS: set print dialog up with page attributes when no printer is installed
When the print dialog is opened without a printer installed, then the printer's output format is PDF rather than native. In this case, we need to set the NSPrintInfo with some page atttributes explicitly, and not default to the application-wide NSPrintInfo.sharedPrintInfo. Otherwise, the print dialog will show the wrong page size and orientation, and the printer will not have the previously set values when the dialog returns. The dialog always shows the wrong values for the page margins (only available through the presets dialog), but the printer's values are not overridden. Also, the print range is taken care of correctly by the code further down in this function, irrespective of the printer's output format. Note: this cannot be unit tested as we need to open the native print dialog on a system without printer installed, and compare the values we set on the printer before opening the dialog with the values after the dialog was successfully finished via PDF->Save as PDF. Fixes: QTBUG-100188 Pick-to: 6.4 6.3 6.2 Change-Id: I8f1561e054f6a867b131111845c9b061778e4eb0 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/printsupport/dialogs/qprintdialog_mac.mm')
-rw-r--r--src/printsupport/dialogs/qprintdialog_mac.mm8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm
index fc2432240d..6671afae52 100644
--- a/src/printsupport/dialogs/qprintdialog_mac.mm
+++ b/src/printsupport/dialogs/qprintdialog_mac.mm
@@ -187,7 +187,13 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality)
printInfo = static_cast<QMacPrintEngine *>(printer->printEngine())->printInfo();
[printInfo retain];
} else {
- printInfo = [NSPrintInfo.sharedPrintInfo retain];
+ const QPageLayout pageLayout = printer->pageLayout();
+ // initialize the printInfo using the dictionary from the application-wide print info
+ const auto dictionary = [NSPrintInfo.sharedPrintInfo dictionary];
+ printInfo = [[NSPrintInfo alloc] initWithDictionary:dictionary];
+ printInfo.orientation = pageLayout.orientation() == QPageLayout::Landscape
+ ? NSPaperOrientationLandscape : NSPaperOrientationPortrait;
+ printInfo.paperSize = pageLayout.pageSize().size(QPageSize::Point).toCGSize();
}
// It seems the only way that PM lets you use all is if the minimum