From ef14e775de9932fecea5443b976b950c311ba938 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:02:21 +0100 Subject: QMenu: Move exec(), popup() to private class Task-number: QTBUG-78966 Change-Id: I69257dc52706449a1e0babfc29e5f93f63d9291b Reviewed-by: Volker Hilsheimer Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets/widgets/qmenu_p.h') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index efbbc099a1..7d2d0ab487 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -351,6 +351,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; + void popup(const QPoint &p, QAction *atAction); + QAction *exec(const QPoint &p, QAction *action); //selection static QMenu *mouseDown; -- cgit v1.2.3 From a78d66743171557d79b16c08be775e3ac15bb4ef Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:33:50 +0100 Subject: Fix positioning of dynamically populated QToolButton::MenuButtonPopup's in screen corners The existing code positioning the menu in QToolButtonPrivate::popupTimerDone() had a clause checking whether any receivers were connnected to QMenu::aboutToShow() causing the sizeHint to be -1,-1 in that case (apparently trying to accommodate menus populated in slots). In that case, the checking for screen borders would not work, causing the similar checks in QMenu::popup() to trigger, potentially positioning the menu over the mouse. To solve this dilemma, add a parameter taking a std::function calulating the position of the menu from the sizeHint to QMenuPrivate::exec()/popup() and invoke that in QMenuPrivate::popup() after emitting QMenu::aboutToShow() when the sizeHint is known. Fixes: QTBUG-78966 Change-Id: I180bd2dc7eadcaca6cadca13745ed4a2dd89e412 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmenu_p.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets/qmenu_p.h') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 7d2d0ab487..02fe9f31a1 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -64,6 +64,8 @@ #include +#include + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +304,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function; + QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), @@ -351,8 +355,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; - void popup(const QPoint &p, QAction *atAction); - QAction *exec(const QPoint &p, QAction *action); + void popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction = {}); + QAction *exec(const QPoint &p, QAction *action, PositionFunction positionFunction = {}); //selection static QMenu *mouseDown; -- cgit v1.2.3