path: root/src
diff options
authorMorten Johan Sørvig <>2017-04-05 12:39:15 +0200
committerMorten Johan Sørvig <>2017-04-06 09:42:23 +0000
commit5e76cb16924a42cb020786f45cc3494dd5836c5c (patch)
treed07fc1fb83778b9e2ac98ba04a43d14f305ecb89 /src
parentefb84b6189f9e98c6dd29c22f00ad760445196c2 (diff)
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 <>
Diffstat (limited to 'src')
1 files 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;