Skip to content
Permalink
Browse files
physical dpi is only available after showEvent
  • Loading branch information
m-kuhn committed Jul 13, 2021
1 parent 0f25f99 commit 598e2bd31f53bddc5c1b416dd1b7c443f2dc9aeb
Showing with 22 additions and 15 deletions.
  1. +2 −0 python/gui/auto_generated/qgsmapcanvas.sip.in
  2. +19 −15 src/gui/qgsmapcanvas.cpp
  3. +1 −0 src/gui/qgsmapcanvas.h
@@ -1314,6 +1314,8 @@ called when panning is in action, reset indicates end of panning
virtual void dropEvent( QDropEvent *event );


virtual void showEvent( QShowEvent *event );




@@ -206,26 +206,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )

QSize s = viewport()->size();
mSettings.setOutputSize( s );
updateDevicePixelFromScreen();

setSceneRect( 0, 0, s.width(), s.height() );
mScene->setSceneRect( QRectF( 0, 0, s.width(), s.height() ) );

moveCanvasContents( true );


// keep device pixel ratio up to date on screen or resolution change
if ( window()->windowHandle() )
{
connect( window()->windowHandle(), &QWindow::screenChanged, this, [ = ]( QScreen * )
{
disconnect( mScreenDpiChangedConnection );
mScreenDpiChangedConnection = connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsMapCanvas::updateDevicePixelFromScreen );
updateDevicePixelFromScreen();
} );

mScreenDpiChangedConnection = connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsMapCanvas::updateDevicePixelFromScreen );
}

connect( &mMapUpdateTimer, &QTimer::timeout, this, &QgsMapCanvas::mapUpdateTimeout );
mMapUpdateTimer.setInterval( 250 );

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

void QgsMapCanvas::showEvent( QShowEvent *event )
{
Q_UNUSED( event )
updateDevicePixelFromScreen();
// keep device pixel ratio up to date on screen or resolution change
if ( window()->windowHandle() )
{
connect( window()->windowHandle(), &QWindow::screenChanged, this, [ = ]( QScreen * )
{
disconnect( mScreenDpiChangedConnection );
mScreenDpiChangedConnection = connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsMapCanvas::updateDevicePixelFromScreen );
updateDevicePixelFromScreen();
} );

mScreenDpiChangedConnection = connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsMapCanvas::updateDevicePixelFromScreen );
}
}

QPoint QgsMapCanvas::mouseLastXY()
{
return mCanvasProperties->mouseLastXY;
@@ -1183,6 +1183,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContex

void dropEvent( QDropEvent *event ) override;

void showEvent( QShowEvent *event ) override;

/// implementation struct
class CanvasProperties;

0 comments on commit 598e2bd

Please sign in to comment.