@@ -206,26 +206,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
206
206
207
207
QSize s = viewport ()->size ();
208
208
mSettings .setOutputSize ( s );
209
- updateDevicePixelFromScreen ();
209
+
210
210
setSceneRect ( 0 , 0 , s.width (), s.height () );
211
211
mScene ->setSceneRect ( QRectF ( 0 , 0 , s.width (), s.height () ) );
212
212
213
213
moveCanvasContents ( true );
214
214
215
-
216
- // keep device pixel ratio up to date on screen or resolution change
217
- if ( window ()->windowHandle () )
218
- {
219
- connect ( window ()->windowHandle (), &QWindow::screenChanged, this , [ = ]( QScreen * )
220
- {
221
- disconnect ( mScreenDpiChangedConnection );
222
- mScreenDpiChangedConnection = connect ( window ()->windowHandle ()->screen (), &QScreen::physicalDotsPerInchChanged, this , &QgsMapCanvas::updateDevicePixelFromScreen );
223
- updateDevicePixelFromScreen ();
224
- } );
225
-
226
- mScreenDpiChangedConnection = connect ( window ()->windowHandle ()->screen (), &QScreen::physicalDotsPerInchChanged, this , &QgsMapCanvas::updateDevicePixelFromScreen );
227
- }
228
-
229
215
connect ( &mMapUpdateTimer , &QTimer::timeout, this , &QgsMapCanvas::mapUpdateTimeout );
230
216
mMapUpdateTimer .setInterval ( 250 );
231
217
@@ -2592,6 +2578,24 @@ void QgsMapCanvas::dropEvent( QDropEvent *event )
2592
2578
}
2593
2579
}
2594
2580
2581
+ void QgsMapCanvas::showEvent ( QShowEvent *event )
2582
+ {
2583
+ Q_UNUSED ( event )
2584
+ updateDevicePixelFromScreen ();
2585
+ // keep device pixel ratio up to date on screen or resolution change
2586
+ if ( window ()->windowHandle () )
2587
+ {
2588
+ connect ( window ()->windowHandle (), &QWindow::screenChanged, this , [ = ]( QScreen * )
2589
+ {
2590
+ disconnect ( mScreenDpiChangedConnection );
2591
+ mScreenDpiChangedConnection = connect ( window ()->windowHandle ()->screen (), &QScreen::physicalDotsPerInchChanged, this , &QgsMapCanvas::updateDevicePixelFromScreen );
2592
+ updateDevicePixelFromScreen ();
2593
+ } );
2594
+
2595
+ mScreenDpiChangedConnection = connect ( window ()->windowHandle ()->screen (), &QScreen::physicalDotsPerInchChanged, this , &QgsMapCanvas::updateDevicePixelFromScreen );
2596
+ }
2597
+ }
2598
+
2595
2599
QPoint QgsMapCanvas::mouseLastXY ()
2596
2600
{
2597
2601
return mCanvasProperties ->mouseLastXY ;
0 commit comments