From 652065b06b338ce2bddea2d4b71d2dd2aa7b3185 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 4 Mar 2024 15:47:34 +0100 Subject: [PATCH] Honor QPrinter::setFullPage(true) on Windows too (no margins) fullPage means the print engine shouldn't add any margins, the application will take care of that. That's already what happens on Linux and Mac, but the Windows print engine was offset-ting everything to the bottom right by the value of the margins, erroneously. As noted in QTBUG-95927, the workaround for this bug was to call printer.setPageMargins(QMargins(0,0,0,0)); when using printer.setFullPage(true), and this fix is compatible with that workaround, existing apps won't be broken. [ChangeLog][QtPrintSupport][Windows] setFullPage(true) now behaves as expected, i.e. the QPrinter margins are ignored and the drawing's (0, 0) is the topleft corner of the page. This is what setFullPage(true) is documented to do, and how it was already working on other operating systems. If this causes regressions in your application, consider removing the call to setFullPage(true) so that the painting honors the margins again. Fixes: QTBUG-119003 Fixes: QTBUG-95927 Change-Id: Ia3d621302bf752833002614303dd64128027163a Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/printsupport/platform/windows/qprintengine_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/printsupport/platform/windows/qprintengine_win.cpp b/src/printsupport/platform/windows/qprintengine_win.cpp index b275b01990..e1ff6f1d83 100644 --- a/src/printsupport/platform/windows/qprintengine_win.cpp +++ b/src/printsupport/platform/windows/qprintengine_win.cpp @@ -1707,7 +1707,8 @@ void QWin32PrintEnginePrivate::updateMetrics() m_paintSizeMM = QSize(qRound(sizeMM.width()), qRound(sizeMM.height())); // Calculate the origin using the physical device pixels, not our paint pixels // Origin is defined as User Margins - Device Margins - QMarginsF margins = m_pageLayout.margins(QPageLayout::Millimeter) / 25.4; + const bool isFullPage = (m_pageLayout.mode() == QPageLayout::FullPageMode); + const QMarginsF margins = isFullPage ? QMarginsF() : (m_pageLayout.margins(QPageLayout::Millimeter) / 25.4); origin_x = qRound(pageScaleX * margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX); origin_y = qRound(pageScaleY * margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY); }