summaryrefslogtreecommitdiffhomepage
path: root/compat/qt-dpi.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/qt-dpi.hpp')
-rw-r--r--compat/qt-dpi.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/compat/qt-dpi.hpp b/compat/qt-dpi.hpp
new file mode 100644
index 00000000..fc17a062
--- /dev/null
+++ b/compat/qt-dpi.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <algorithm>
+#include <QWidget>
+
+static inline double screen_dpi(const QPaintDevice* widget)
+{
+ const auto& x = *widget;
+#ifdef _WIN32
+ return std::max(x.devicePixelRatioF(), 1.);
+#else
+ return std::max(std::max(x.logicalDpiX()/(double)x.physicalDpiX(), x.devicePixelRatioF()), 1.);
+#endif
+}
+
+template<typename self>
+struct screen_dpi_mixin
+{
+protected:
+ double screen_dpi() const
+ {
+ return ::screen_dpi(static_cast<const self*>(this));
+ }
+};