diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-12-05 09:33:50 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-23 16:46:51 +0100 |
commit | a78d66743171557d79b16c08be775e3ac15bb4ef (patch) | |
tree | 5dfb8ef0668847dfe90f396ee2c0dda1e227ca56 /src/widgets/widgets/qmenu_p.h | |
parent | ef14e775de9932fecea5443b976b950c311ba938 (diff) |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmenu_p.h')
-rw-r--r-- | src/widgets/widgets/qmenu_p.h | 8 |
1 files changed, 6 insertions, 2 deletions
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 <qpa/qplatformmenu.h> +#include <functional> + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +304,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function<QPoint(const QSize &)>; + 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; |