From 5e76cb16924a42cb020786f45cc3494dd5836c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 5 Apr 2017 12:39:15 +0200 Subject: [PATCH] Fix menu position when highdpi scaling Certain display and scale factor configurations would cause menus to pop up in incorrect locations or not be shown at all. This was due to QDesktopWidget::screenNumber() having a toNativePixels(QRect, QWindow) call which requires that QWindow::screen() returns the correct screen. Break the circular dependency by converting coordinates the other way for the intersection test: transform screen geometry to device independent coordinates. Task-number: QTBUG-58329 Change-Id: I5621de89a9a2b8df44bdae528baf011fc111eba3 Reviewed-by: Paolo Angelelli Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/widgets/kernel/qdesktopwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index eee818b685..1e6fbfd239 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -269,12 +269,13 @@ int QDesktopWidget::screenNumber(const QWidget *w) const QRect frame = w->frameGeometry(); if (!w->isWindow()) frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0))); - const QRect nativeFrame = QHighDpi::toNativePixels(frame, winHandle); QScreen *widgetScreen = Q_NULLPTR; int largestArea = 0; foreach (QScreen *screen, screens) { - const QRect intersected = screen->handle()->geometry().intersected(nativeFrame); + const QRect deviceIndependentScreenGeometry = + QHighDpi::fromNativePixels(screen->handle()->geometry(), screen); + const QRect intersected = deviceIndependentScreenGeometry.intersected(frame); int area = intersected.width() * intersected.height(); if (largestArea < area) { widgetScreen = screen;