From 1c67d57312e2b59943ef725e186353a742bf11ae Mon Sep 17 00:00:00 2001 From: siren186 <765495939@qq.com> Date: Fri, 15 Dec 2023 09:40:55 +0800 Subject: [PATCH] Add high DPI support for native window --- qtwinmigrate/src/qwinhost.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/qtwinmigrate/src/qwinhost.cpp b/qtwinmigrate/src/qwinhost.cpp index c1f84b0..2895b57 100644 --- a/qtwinmigrate/src/qwinhost.cpp +++ b/qtwinmigrate/src/qwinhost.cpp @@ -10,6 +10,7 @@ #include "qwinhost.h" #include +#include #include #if QT_VERSION >= 0x050000 @@ -270,7 +271,13 @@ void QWinHost::showEvent(QShowEvent *e) QWidget::showEvent(e); if (hwnd) - SetWindowPos(hwnd, HWND_TOP, 0, 0, width(), height(), SWP_SHOWWINDOW); + { + // High DPI Support + qreal dpr = this->screen()->devicePixelRatio(); + qreal w = width() * dpr; + qreal h = height() * dpr; + SetWindowPos(hwnd, HWND_TOP, 0, 0, (int)w, (int)h, SWP_SHOWWINDOW); + } } /*! @@ -292,7 +299,13 @@ void QWinHost::resizeEvent(QResizeEvent *e) QWidget::resizeEvent(e); if (hwnd) - SetWindowPos(hwnd, HWND_TOP, 0, 0, width(), height(), 0); + { + // High DPI Support + qreal dpr = this->screen()->devicePixelRatio(); + qreal w = width() * dpr; + qreal h = height() * dpr; + SetWindowPos(hwnd, HWND_TOP, 0, 0, (int)w, (int)h, 0); + } } /*!