Skip to content

Commit 8d91a6e

Browse files
committed
fix device size in decoration item
the size should take the device pixel ration into account fixes #20321
1 parent 7b6d2c0 commit 8d91a6e

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/app/decorations/qgsdecorationcopyright.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ void QgsDecorationCopyright::render( const QgsMapSettings &mapSettings, QgsRende
124124
double textWidth = QgsTextRenderer::textWidth( context, mTextFormat, displayStringList, &fm );
125125
double textHeight = QgsTextRenderer::textHeight( context, mTextFormat, displayStringList, QgsTextRenderer::Point, &fm );
126126

127-
int deviceHeight = context.painter()->device()->height();
128-
int deviceWidth = context.painter()->device()->width();
127+
QPaintDevice *device = context.painter()->device();
128+
#if QT_VERSION < 0x050600
129+
int deviceHeight = device->height() / device->devicePixelRatio();
130+
int deviceWidth = device->width() / device->devicePixelRatio();
131+
#else
132+
int deviceHeight = device->height() / device->devicePixelRatioF();
133+
int deviceWidth = device->width() / device->devicePixelRatioF();
134+
#endif
129135

130136
float xOffset( 0 ), yOffset( 0 );
131137

src/app/decorations/qgsdecorationnortharrow.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,14 @@ void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRend
168168
( centerYDouble * std::cos( radiansDouble ) )
169169
) - centerYDouble );
170170
// need width/height of paint device
171-
int deviceHeight = context.painter()->device()->height();
172-
int deviceWidth = context.painter()->device()->width();
171+
QPaintDevice *device = context.painter()->device();
172+
#if QT_VERSION < 0x050600
173+
int deviceHeight = device->height() / device->devicePixelRatio();
174+
int deviceWidth = device->width() / device->devicePixelRatio();
175+
#else
176+
int deviceHeight = device->height() / device->devicePixelRatioF();
177+
int deviceWidth = device->width() / device->devicePixelRatioF();
178+
#endif
173179

174180
// Set margin according to selected units
175181
int xOffset = 0;

src/app/decorations/qgsdecorationscalebar.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,14 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
177177
return;
178178

179179
//Get canvas dimensions
180-
int deviceHeight = context.painter()->device()->height();
181-
int deviceWidth = context.painter()->device()->width();
180+
QPaintDevice *device = context.painter()->device();
181+
#if QT_VERSION < 0x050600
182+
int deviceHeight = device->height() / device->devicePixelRatio();
183+
int deviceWidth = device->width() / device->devicePixelRatio();
184+
#else
185+
int deviceHeight = device->height() / device->devicePixelRatioF();
186+
int deviceWidth = device->width() / device->devicePixelRatioF();
187+
#endif
182188

183189
//Get map units per pixel. This can be negative at times (to do with
184190
//projections) and that just confuses the rest of the code in this

0 commit comments

Comments
 (0)