QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsscreenhelper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsscreenhelper.h
3 ---------------
4 Date : August 2022
5 Copyright : (C) 2022 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSSCREENHELPER_H
16#define QGSSCREENHELPER_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20
21#include <QObject>
22#include <QRect>
23
24class QWidget;
25class QScreen;
26class QWindow;
27
35class GUI_EXPORT QgsScreenHelper : public QObject
36{
37 Q_OBJECT
38
39 public:
40
44 QgsScreenHelper( QWidget *parent SIP_TRANSFERTHIS );
45
49 QScreen *screen();
50
54 QWindow *windowHandle();
55
61 double screenDpi() const { return mScreenDpi; }
62
70 QRect availableGeometry() const { return mAvailableGeometry; }
71
72 signals:
73
79 void screenDpiChanged( double dpi );
80
86 void availableGeometryChanged( const QRect &geometry );
87
88 protected:
89 bool eventFilter( QObject *watched, QEvent *event ) override;
90
91 private slots:
92
93 void updateDevicePixelFromScreen();
94 void updateAvailableGeometryFromScreen();
95
96 private:
97
98 QWidget *mWidget = nullptr;
99
100 double mScreenDpi = 96.0;
101 QMetaObject::Connection mScreenDpiChangedConnection;
102
103 QRect mAvailableGeometry;
104 QMetaObject::Connection mAvailableGeometryChangedConnection;
105
106};
107
108
109#endif // QGSSCREENHELPER_H
A utility class for dynamic handling of changes to screen properties.
QRect availableGeometry() const
Returns the current screen available geometry in pixels.
double screenDpi() const
Returns the current screen DPI for the screen that the parent widget appears on.
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.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53