From e7d5b521d4df48040b6ac0f8150f60245a6179f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Thu, 7 Apr 2022 11:00:26 +0200 Subject: QAction: Add setMenu() and menu() After the changes in Qt6 related to moving QAction completely to QtGui, the 'on-demand' functions associated to QMenu were not properly exposed. This patch manually adds setMenu()/menu() using QObject's. A simple test case was added. [ChangeLog] QAction.setMenu() and QAction.menu() were implemented. Done-with: Friedemann Kleint Fixes: PYSIDE-1627 Change-Id: Ib8102a9cf513ee2e13ff71751b1167ca0146af31 Reviewed-by: Shyamnath Premnadh Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Qt CI Bot (cherry picked from commit c85df0b37c4e91ff4d61091c06d0f75734356990) Reviewed-by: Qt Cherry-pick Bot --- sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml | 8 ++++++-- sources/pyside6/PySide6/glue/qtgui.cpp | 6 ++++++ sources/pyside6/tests/QtWidgets/qaction_test.py | 13 ++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index aaf90b30f..dfc302da6 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -227,11 +227,15 @@ - + + + + + - + diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp index 935d33bda..ff574e557 100644 --- a/sources/pyside6/PySide6/glue/qtgui.cpp +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -136,6 +136,12 @@ QAccessibleInterface *PySideAccessibleFactory::callFactories(const QString &key, PySideAccessibleFactory::ensureInstance()->installFactory(%1); // @snippet qaccessible-installfactory +// @snippet qaction-menu +// %CPPSELF->menu(); // pretend it was called. +QObject *object = %CPPSELF->menu(); +%PYARG_0 = %CONVERTTOPYTHON[QObject*](object); +// @snippet qaction-menu + // @snippet glgetshadersource GLsizei bufSize = 4096; GLsizei length = bufSize - 1; diff --git a/sources/pyside6/tests/QtWidgets/qaction_test.py b/sources/pyside6/tests/QtWidgets/qaction_test.py index 6f9b1afec..26d3e65e6 100644 --- a/sources/pyside6/tests/QtWidgets/qaction_test.py +++ b/sources/pyside6/tests/QtWidgets/qaction_test.py @@ -36,7 +36,7 @@ from init_paths import init_test_paths init_test_paths(False) from PySide6.QtGui import QAction -from PySide6.QtWidgets import QWidget +from PySide6.QtWidgets import QWidget, QMenu from helper.usesqapplication import UsesQApplication @@ -73,6 +73,17 @@ class SetShortcutTest(UsesQApplication): s2 = action.shortcut() self.assertEqual(s2, shortcut) + def testMenu(self): + # Test the setMenu()/menu() old functionality removed in Qt6 + # that was added via helper functions. + menu = QMenu("menu") + action = QAction("action") + + # Using QAction::setMenu(QObject*) + action.setMenu(menu) + + self.assertEqual(action.menu(), menu) + if __name__ == '__main__': unittest.main() -- cgit v1.2.3