diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-03-07 14:44:14 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-11 12:58:58 +0200 |
commit | 7199498fb9cbfb5afc043ddb0e630c8ffad5240b (patch) | |
tree | 2c419a45ba9aae93895c96a8991dca459c753c52 /src/widgets | |
parent | cf5d9e9eb5c4ad77f68aa2787bfb81550ded9c23 (diff) |
QPushButton: use QMenu::popup instead of exec to show menu
QMenu::exec opens a blocking loop, which is problematic for webassembly.
Replace with QMenu::popup, and reset the down-state of the button when
the menu is about to hide. QMenu emits aboutToHide immediately before
existing the event loop in the hideEvent override, so the timing is the
same.
Change-Id: Iccb418d10fcb25f6ad1f73f9cdce6ea6581bd73b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qpushbutton.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index ec882db175..74ec79fae2 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -575,17 +575,14 @@ void QPushButtonPrivate::_q_popupPressed() QPoint menuPos = adjustedMenuPosition(); - QPointer<QPushButton> guard(q); - QMenuPrivate::get(menu)->causedPopup.widget = guard; + QMenuPrivate::get(menu)->causedPopup.widget = q; //Because of a delay in menu effects, we must keep track of the //menu visibility to avoid flicker on button release menuOpen = true; - menu->exec(menuPos); - if (guard) { - menuOpen = false; - q->setDown(false); - } + QObject::connect(menu, &QMenu::aboutToHide, + q, [q]{ q->setDown(false); }, Qt::SingleShotConnection); + menu->popup(menuPos); } QPoint QPushButtonPrivate::adjustedMenuPosition() |