diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index f662a34129d2a648ebc77c910e9a7a62d503f7a0..5f7c7507115c10a21f42993972927f20e16a89b2 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1870,20 +1870,27 @@ QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) const Q_Q(const QWindow); QScreen *currentScreen = q->screen(); QScreen *fallback = currentScreen; - QPoint center = newGeometry.center(); - if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) { - const auto screens = currentScreen->virtualSiblings(); - for (QScreen* screen : screens) { - if (screen->geometry().contains(center)) + const auto screens = currentScreen->virtualSiblings(); + int largestIntersectionArea = 0; + if (!q->parent() && currentScreen) { + for (QScreen *screen : screens) { + QRect nativeScreenGeometry = QHighDpi::toNativePixels(screen->geometry(), screen); + QRect nativeGeometry = QHighDpi::toNativePixels(newGeometry, screen); + if (nativeScreenGeometry.contains(nativeGeometry.center())) { return screen; - if (screen->geometry().intersects(newGeometry)) + } + QRect intersection = nativeScreenGeometry.intersected(nativeGeometry); + int intesectionAria = intersection.width() * intersection.height() * screen->devicePixelRatio(); + if (!intersection.isEmpty() && intesectionAria > largestIntersectionArea) + { + largestIntersectionArea = intesectionAria; fallback = screen; + } } } return fallback; } - /*! Returns the geometry of the window, excluding its window frame. diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 52d35bc39cd157db930314415757a82c7e9c30bb..61c71f49ea3d739f19234f3098a45f190166f18f 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2025,6 +2025,12 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT * // are currently doing. m_data.customMargins *= scale; } + else { + // Moving frameless windows between screens with different DPI is + // sensitive to rounding errors, so since we don't need to scale any + // margins we return without handling this message to avoid that. + return; + } const QSize windowSize = (geometry().size() * scale).grownBy((margins * scale) + customMargins()); SIZE *size = reinterpret_cast(lParam);