1
0
forked from pool/libqt5-qtbase
libqt5-qtbase/0001-Revert-QMenu-hide-when-a-QWidgetAction-fires-the-tri.patch

140 lines
4.5 KiB
Diff
Raw Normal View History

From 9928d66764337494d0e99208a3418fcd01ac3e66 Mon Sep 17 00:00:00 2001
From: Fabian Vogt <fabian@ritter-vogt.de>
Date: Wed, 27 May 2020 10:48:45 +0200
Subject: [PATCH] Revert "QMenu: hide when a QWidgetAction fires the trigged
signal"
This reverts commit b4669b919048c1dbdac2b3e9b2e79f3d023aa078.
---
src/widgets/widgets/qmenu.cpp | 9 +--
.../auto/widgets/widgets/qmenu/tst_qmenu.cpp | 79 -------------------
2 files changed, 4 insertions(+), 84 deletions(-)
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 865e3b2fb6..2878344f07 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -1470,9 +1470,6 @@ void QMenuPrivate::_q_actionTriggered()
}
}
activateCausedStack(list, action, QAction::Trigger, false);
- // if a widget action fires, we need to hide the menu explicitly
- if (qobject_cast<QWidgetAction*>(action))
- hideUpToMenuBar();
}
}
}
@@ -1640,8 +1637,10 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action)
Widgets can be inserted into menus with the QWidgetAction class.
Instances of this class are used to hold widgets, and are inserted
- into menus with the addAction() overload that takes a QAction. If the
- QWidgetAction fires the triggered() signal, the menu will close.
+ into menus with the addAction() overload that takes a QAction.
+
+ Conversely, actions can be added to widgets with the addAction(),
+ addActions() and insertAction() functions.
\warning To make QMenu visible on the screen, exec() or popup() should be
used instead of show().
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index 5a24995caf..22494f3d24 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -116,7 +116,6 @@ private slots:
void QTBUG20403_nested_popup_on_shortcut_trigger();
void QTBUG47515_widgetActionEnterLeave();
void QTBUG8122_widgetActionCrashOnClose();
- void widgetActionTriggerClosesMenu();
void QTBUG_10735_crashWithDialog();
#ifdef Q_OS_MAC
@@ -1408,84 +1407,6 @@ void tst_QMenu::QTBUG8122_widgetActionCrashOnClose()
QTRY_VERIFY(menu->isHidden());
}
-/*!
- Test that a QWidgetAction that fires closes the menus that it is in.
-*/
-void tst_QMenu::widgetActionTriggerClosesMenu()
-{
- class ButtonAction : public QWidgetAction
- {
- public:
- ButtonAction()
- : QWidgetAction(nullptr)
- {}
-
- void click()
- {
- if (pushButton)
- pushButton->click();
- }
-
- protected:
- QWidget *createWidget(QWidget *parent)
- {
- QPushButton *button = new QPushButton(QLatin1String("Button"), parent);
- connect(button, &QPushButton::clicked, this, &QAction::trigger);
-
- if (!pushButton)
- pushButton = button;
- return button;
- }
-
- private:
- QPointer<QPushButton> pushButton;
- };
-
- QMenu menu;
- QMenu submenu;
-
- int menuTriggeredCount = 0;
- int menuAboutToHideCount = 0;
- QAction *actionTriggered = nullptr;
-
- connect(&menu, &QMenu::triggered, this, [&](QAction *action){
- ++menuTriggeredCount;
- actionTriggered = action;
- });
- connect (&menu, &QMenu::aboutToHide, this, [&](){
- ++menuAboutToHideCount;
- });
-
- QAction regularAction(QLatin1String("Action"));
- ButtonAction widgetAction;
-
- submenu.addAction(&regularAction);
- submenu.addAction(&widgetAction);
-
- menu.addMenu(&submenu);
- menu.addAction(&regularAction);
- menu.addAction(&widgetAction);
-
- menu.popup(QPoint(200,200));
- submenu.popup(QPoint(250,250));
- if (!QTest::qWaitForWindowExposed(&menu) || !QTest::qWaitForWindowExposed(&submenu))
- QSKIP("Failed to show menus, aborting test");
-
- regularAction.trigger();
- QVERIFY(menu.isVisible());
- QVERIFY(submenu.isVisible());
- QCOMPARE(menuTriggeredCount, 1);
- QCOMPARE(actionTriggered, &regularAction);
- menuTriggeredCount = 0;
- actionTriggered = nullptr;
-
- widgetAction.click();
- QVERIFY(!menu.isVisible());
- QVERIFY(!submenu.isVisible());
- QCOMPARE(menuTriggeredCount, 1);
- QCOMPARE(menuAboutToHideCount, 1);
- QCOMPARE(actionTriggered, &widgetAction);
-}
class MyMenu : public QMenu
{
--
2.25.1