28 mWidget->installEventFilter(
this );
42 if ( QWidget *window = mWidget->window() )
43 return window->windowHandle();
50 if ( watched != mWidget )
53 switch ( event->type() )
57 updateDevicePixelFromScreen();
58 updateAvailableGeometryFromScreen();
63 connect( handle, &QWindow::screenChanged,
this, [ = ]( QScreen * )
65 disconnect( mScreenDpiChangedConnection );
66 disconnect( mAvailableGeometryChangedConnection );
70 mScreenDpiChangedConnection = connect( windowHandleInLambda->screen(), &QScreen::physicalDotsPerInchChanged,
this, &QgsScreenHelper::updateDevicePixelFromScreen );
71 updateDevicePixelFromScreen();
73 mAvailableGeometryChangedConnection = connect( windowHandleInLambda->screen(), &QScreen::availableGeometryChanged,
this, &QgsScreenHelper::updateAvailableGeometryFromScreen );
74 updateAvailableGeometryFromScreen();
78 mScreenDpiChangedConnection = connect( handle->screen(), &QScreen::physicalDotsPerInchChanged,
this, &QgsScreenHelper::updateDevicePixelFromScreen );
79 mAvailableGeometryChangedConnection = connect( handle->screen(), &QScreen::availableGeometryChanged,
this, &QgsScreenHelper::updateAvailableGeometryFromScreen );
91void QgsScreenHelper::updateDevicePixelFromScreen()
95 const double newDpi =
screen->physicalDotsPerInch();
104void QgsScreenHelper::updateAvailableGeometryFromScreen()
108 const QRect newGeometry =
screen->availableGeometry();
109 if ( newGeometry != mAvailableGeometry )
111 mAvailableGeometry = newGeometry;
QWindow * windowHandle()
Returns the window handle for the window the parent widget is associated with, or nullptr.
QScreen * screen()
Returns the screen that the parent widget appears on, or nullptr.
bool eventFilter(QObject *watched, QEvent *event) override
QgsScreenHelper(QWidget *parent)
Constructor for QgsScreenHelper for the specified parent widget.
void availableGeometryChanged(const QRect &geometry)
Emitted whenever the available geometry of the screen associated with the widget is changed.
void screenDpiChanged(double dpi)
Emitted whenever the screen dpi associated with the widget is changed.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)