diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 8969e4e1837..b4452a096c7 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2450,9 +2450,11 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po } } - // do nothing if we don't have a valid size, e.g. when all actions are invisible + // Do nothing if we don't have a valid size, e.g. when all actions are invisible + // and there are no child widgets. const auto rectIsNull = [](const QRect &rect) { return rect.isNull(); }; - if (std::all_of(actionRects.cbegin(), actionRects.cend(), rectIsNull)) { + if (q->childrenRect().isEmpty() + && std::all_of(actionRects.cbegin(), actionRects.cend(), rectIsNull)) { eventLoop = nullptr; syncAction = nullptr; return; diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 968cf60bc41..7edbda70c0d 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -2179,6 +2179,13 @@ void tst_QMenu::invisibleActions() contextMenu.popup(globalPos); QVERIFY(!contextMenu.isVisible()); QVERIFY(!contextMenu.exec()); + + // a QMenu might not have any (visible) actions, but still have contents + QPushButton *buttonInMenu = new QPushButton(&contextMenu); + buttonInMenu->show(); + + contextMenu.popup(globalPos); + QVERIFY(contextMenu.isVisible()); } #if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN)