summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2023-11-07 19:58:26 +0100
committerJøger Hansegård <joger.hansegard@qt.io>2023-11-08 18:24:18 +0100
commit70404a2773293e4f3a763aa2f057f1d6569e8661 (patch)
treeaa4e2e75725b2359b2d5f507b8bc47f5a4ebd711
parenta8df174369cecd90f14dac85bf162353b7cb25d1 (diff)
Prevent oversized QToolButton menu from moving to primary screen
The QMenu pop-up used with a QToolButton could unexpectedly move to the primary screen if it was too big to fit on the owning widget's screen. The cause of the issue is that QMenu is a top-level window, and can not infer its screen from any parents. Its positioning is therefore done using heuristics in QToolButton. These heuristics attempt to calculate a best guess point relative to the screen that contains the QToolButton. If these heuristics result in a point that is outside all screens, the QMenu's own screen takes precedence, and this is always the primary screen. This way, the QMenu ends up at the calculated position, but relative to the wrong screen. This patch works around this issue by ensuring that the first estimate for the pop-up position is always within the same screen as the QToolButton. The danger with this workaround is that the menu may end up in an inconvenient location. This does, however, seem to be handled by subsequent adjustments in QMenuPrivate::popup. Fixes: QTBUG-118695 Pick-to: 6.6 6.5 Change-Id: Ibb4a1c82e827c57bbb0798a6c6f5eecb6d639c62 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/widgets/qtoolbutton.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp
index 20de316b6d..f3e3c8261e 100644
--- a/src/widgets/widgets/qtoolbutton.cpp
+++ b/src/widgets/widgets/qtoolbutton.cpp
@@ -725,8 +725,13 @@ static QPoint positionMenu(const QToolButton *q, bool horizontal,
}
}
}
+
+ // QTBUG-118695 Force point inside the current screen. If the returned point
+ // is not found inside any screen, QMenu's positioning logic kicks in without
+ // taking the QToolButton's screen into account. This can cause the menu to
+ // end up on primary monitor, even if the QToolButton is on a non-primary monitor.
p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
- p.ry() += 1;
+ p.ry() = qMax(screen.top(), qMin(p.y() + 1, screen.bottom()));
return p;
}