Skip to content
Permalink
Browse files

[qt6] QPrinter api changed

  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 27, 2021
1 parent cdde805 commit 9f6502e32d46c14aa89b213adf05f8be16178128
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/core/qgsmaprenderertask.cpp
@@ -196,11 +196,20 @@ bool QgsMapRendererTask::run()
QPrinter printer;
printer.setOutputFileName( component.sourcePdfPath );
printer.setOutputFormat( QPrinter::PdfFormat );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
printer.setOrientation( QPrinter::Portrait );
// paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
QSizeF outputSize = mMapSettings.outputSize();
printer.setPaperSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPrinter::Millimeter );
printer.setPageMargins( 0, 0, 0, 0, QPrinter::Millimeter );
#else
printer.setPageOrientation( QPageLayout::Orientation::Portrait );
// paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
QSizeF outputSize = mMapSettings.outputSize();
QPageSize pageSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPageSize::Unit::Millimeter );
printer.setPageSize( pageSize );
printer.setPageMargins( QMarginsF( 0, 0, 0, 0 ) );
#endif
printer.setResolution( mMapSettings.outputDpi() );

QPainter p( &printer );
@@ -472,11 +481,20 @@ void QgsMapRendererTask::prepare()
mPrinter.reset( new QPrinter() );
mPrinter->setOutputFileName( mFileName );
mPrinter->setOutputFormat( QPrinter::PdfFormat );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
mPrinter->setOrientation( QPrinter::Portrait );
// paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
QSizeF outputSize = mMapSettings.outputSize();
mPrinter->setPaperSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPrinter::Millimeter );
mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Millimeter );
#else
mPrinter->setPageOrientation( QPageLayout::Orientation::Portrait );
// paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
QSizeF outputSize = mMapSettings.outputSize();
QPageSize pageSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPageSize::Unit::Millimeter );
mPrinter->setPageSize( pageSize );
mPrinter->setPageMargins( QMarginsF( 0, 0, 0, 0 ) );
#endif
mPrinter->setResolution( mMapSettings.outputDpi() );

if ( !mForceRaster )

0 comments on commit 9f6502e

Please sign in to comment.