Skip to content

Commit 598e2bd

Browse files
committedJul 13, 2021
physical dpi is only available after showEvent
1 parent 0f25f99 commit 598e2bd

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed
 

‎python/gui/auto_generated/qgsmapcanvas.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,8 @@ called when panning is in action, reset indicates end of panning
13141314
virtual void dropEvent( QDropEvent *event );
13151315

13161316

1317+
virtual void showEvent( QShowEvent *event );
1318+
13171319

13181320

13191321

‎src/gui/qgsmapcanvas.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
206206

207207
QSize s = viewport()->size();
208208
mSettings.setOutputSize( s );
209-
updateDevicePixelFromScreen();
209+
210210
setSceneRect( 0, 0, s.width(), s.height() );
211211
mScene->setSceneRect( QRectF( 0, 0, s.width(), s.height() ) );
212212

213213
moveCanvasContents( true );
214214

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-
229215
connect( &mMapUpdateTimer, &QTimer::timeout, this, &QgsMapCanvas::mapUpdateTimeout );
230216
mMapUpdateTimer.setInterval( 250 );
231217

@@ -2592,6 +2578,24 @@ void QgsMapCanvas::dropEvent( QDropEvent *event )
25922578
}
25932579
}
25942580

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+
25952599
QPoint QgsMapCanvas::mouseLastXY()
25962600
{
25972601
return mCanvasProperties->mouseLastXY;

‎src/gui/qgsmapcanvas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContex
11831183

11841184
void dropEvent( QDropEvent *event ) override;
11851185

1186+
void showEvent( QShowEvent *event ) override;
11861187

11871188
/// implementation struct
11881189
class CanvasProperties;

0 commit comments

Comments
 (0)
Please sign in to comment.