From 850d401bb3de889a9bd2e4337abef4d7156f6175 Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Mon, 13 Sep 2021 14:55:55 -0700 Subject: [PATCH] PerScreenDpi | Moving windows between screens with different scale changes the window size (#4064) * Fix window size when dropped on a screen with a different scale setting compared to the one it was dragged from. Note that this fixes a bug that could only be reproduced with the PerScreenDpiAware setting activated - current editor uses SystemDpiAware. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Fix loss of precision warning. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- .../AzQtComponents/Components/FancyDocking.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Components/FancyDocking.cpp b/Code/Framework/AzQtComponents/AzQtComponents/Components/FancyDocking.cpp index d73ebbec28..f60a98f392 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/Components/FancyDocking.cpp +++ b/Code/Framework/AzQtComponents/AzQtComponents/Components/FancyDocking.cpp @@ -2461,6 +2461,18 @@ namespace AzQtComponents placeholderRect.translate(0, -margins.bottom()); } + // Also adjust the placeholderRect by the relative dpi change from the original screen, since setGeometry uses the screen's + // virtualGeometry! + QScreen* fromScreen = dock->screen(); + QScreen* toScreen = Utilities::ScreenAtPoint(placeholderRect.topLeft()); + + if (fromScreen != toScreen) + { + qreal factorRatio = QHighDpiScaling::factor(fromScreen) / QHighDpiScaling::factor(toScreen); + placeholderRect.setWidth(aznumeric_cast(aznumeric_cast(placeholderRect.width()) * factorRatio)); + placeholderRect.setHeight(aznumeric_cast(aznumeric_cast(placeholderRect.height()) * factorRatio)); + } + // Place the floating dock widget makeDockWidgetFloating(dock, placeholderRect); clearDraggingState();