Resize the window when the screen's dpi changes

That's what the MSDN documentation say one should do in the handler
for WM_DPICHANGED

[ChangeLog][QtGui][Windows] Windows are now automatically resized
when they are moved on a screen to adapt to the new pixel ratio.

Task-number: QTBUG-55510
Task-number: QTBUG-48242
Change-Id: I7688f12165f76585d75686e2e94b0fc562627be2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Olivier Goffart 2017-02-13 08:48:25 +01:00 committed by Olivier Goffart (Woboq GmbH)
parent 2b34aefcf0
commit cd2b5f1ada
4 changed files with 24 additions and 3 deletions

View File

@ -56,6 +56,10 @@
# define WM_GESTURE 0x0119
#endif
#ifndef WM_DPICHANGED
# define WM_DPICHANGED 0x02E0
#endif
QT_BEGIN_NAMESPACE
namespace QtWindows
@ -96,6 +100,7 @@ enum WindowsEventType // Simplify event types
FocusInEvent = WindowEventFlag + 17,
FocusOutEvent = WindowEventFlag + 18,
WhatsThisEvent = WindowEventFlag + 19,
DpiChangedEvent = WindowEventFlag + 21,
MouseEvent = MouseEventFlag + 1,
MouseWheelEvent = MouseEventFlag + 2,
CursorEvent = MouseEventFlag + 3,
@ -266,6 +271,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
#endif
case WM_GESTURE:
return QtWindows::GestureEvent;
case WM_DPICHANGED:
return QtWindows::DpiChangedEvent;
default:
break;
}

View File

@ -1088,6 +1088,15 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
return true;
#endif
} break;
case QtWindows::DpiChangedEvent: {
platformWindow->setFlag(QWindowsWindow::WithinDpiChanged);
const RECT *prcNewWindow = reinterpret_cast<RECT *>(lParam);
SetWindowPos(hwnd, NULL, prcNewWindow->left, prcNewWindow->top,
prcNewWindow->right - prcNewWindow->left,
prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
platformWindow->clearFlag(QWindowsWindow::WithinDpiChanged);
return true;
}
#if !defined(QT_NO_SESSIONMANAGER)
case QtWindows::QueryEndSessionApplicationEvent: {
QWindowsSessionManager *sessionManager = platformSessionManager();

View File

@ -2114,8 +2114,12 @@ void QWindowsWindow::setFrameStrutEventsEnabled(bool enabled)
void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const
{
const QWindowsGeometryHint hint(window(), m_data.customMargins);
hint.applyToMinMaxInfo(m_data.hwnd, mmi);
// We don't apply the min/max size hint as we change the dpi, because we did not adjust the
// QScreen of the window yet so we don't have the min/max with the right ratio
if (!testFlag(QWindowsWindow::WithinDpiChanged)) {
const QWindowsGeometryHint hint(window(), m_data.customMargins);
hint.applyToMinMaxInfo(m_data.hwnd, mmi);
}
if ((testFlag(WithinMaximize) || (window()->windowState() == Qt::WindowMinimized))
&& (m_data.flags & Qt::FramelessWindowHint)) {

View File

@ -205,7 +205,8 @@ public:
MaximizeToFullScreen = 0x80000,
InputMethodDisabled = 0x100000,
Compositing = 0x200000,
HasBorderInFullScreen = 0x400000
HasBorderInFullScreen = 0x400000,
WithinDpiChanged = 0x800000,
};
QWindowsWindow(QWindow *window, const QWindowsWindowData &data);