diff options
| author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-01-11 10:13:14 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-06-18 15:28:28 +0200 |
| commit | a45ee7a68e3fbcf99eb31e8a395779cc0a9f3540 (patch) | |
| tree | df3bde78213e01af6037a54e7ac553b61e302f18 | |
| parent | fd3dbb4678526535bb3e50d39dd69d590304890b (diff) | |
PySide6: Add QKey support for the setShortcut method
When this method is used in Qt/C++, the argument gets internally cast
to a QKeyCombination if it is a QKey, but in Python land this is not
automatically covered.
A workaround was for the users to manually cast the QKey, but this
adds an extra step to achieve the same.
This patch adds a new method to QAction and QAbstractButton to use
setShortcut with a QKey as an argument.
Pick-to: 6.1
Change-Id: I9e9ebe16a65cb5aeb26a367faecbbbd414d80e03
Fixes: PYSIDE-907
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
5 files changed, 17 insertions, 3 deletions
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index c04517119..817dd7da0 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -195,6 +195,9 @@ </modify-argument> </modify-function> <modify-function signature="triggered(bool)" allow-thread="yes"/> + <add-function signature="setShortcut(Qt::Key)"> + <inject-code file="../glue/qtgui.cpp" snippet="set-qtkey-shortcut"/> + </add-function> </object-type> <object-type name="QActionGroup"> <enum-type name="ExclusionPolicy" since="5.14"/> diff --git a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml index fdc10559a..c66902163 100644 --- a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml +++ b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml @@ -1156,7 +1156,11 @@ </modify-argument> </modify-function> </object-type> - <object-type name="QAbstractButton"/> + <object-type name="QAbstractButton"> + <add-function signature="setShortcut(Qt::Key)"> + <inject-code file="../glue/qtgui.cpp" snippet="set-qtkey-shortcut"/> + </add-function> + </object-type> <object-type name="QStyle"> <enum-type name="ComplexControl"/> <enum-type name="ContentsType"/> diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp index ef5caa545..6b30952d2 100644 --- a/sources/pyside6/PySide6/glue/qtgui.cpp +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -557,6 +557,10 @@ WId id = %1; %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); // @snippet qwindow-fromWinId +// @snippet set-qtkey-shortcut +%CPPSELF.%FUNCTION_NAME(QKeyCombination(%1)); +// @snippet set-qtkey-shortcut + // @snippet qshortcut-1 %0 = new %TYPE(%1, %2); // @snippet qshortcut-1 diff --git a/sources/pyside6/tests/QtWidgets/add_action_test.py b/sources/pyside6/tests/QtWidgets/add_action_test.py index 1260f4e17..5342b9d55 100644 --- a/sources/pyside6/tests/QtWidgets/add_action_test.py +++ b/sources/pyside6/tests/QtWidgets/add_action_test.py @@ -37,7 +37,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtCore import SLOT +from PySide6.QtCore import Qt, SLOT from PySide6.QtGui import QAction from PySide6.QtWidgets import QMenuBar, QPushButton @@ -62,6 +62,7 @@ class AddActionTest(UsesQApplication): menubar = QMenuBar() action = menubar.addAction("Accounts", self._callback) action.activate(QAction.Trigger) + action.setShortcut(Qt.Key_A) self.assertTrue(self.called) def testWithCppSlot(self): @@ -71,6 +72,7 @@ class AddActionTest(UsesQApplication): widget.setCheckable(True) widget.setChecked(False) action = menubar.addAction("Accounts", widget, SLOT("toggle()")) + action.setShortcut(Qt.Key_A) action.activate(QAction.Trigger) self.assertTrue(widget.isChecked()) diff --git a/sources/pyside6/tests/QtWidgets/qpushbutton_test.py b/sources/pyside6/tests/QtWidgets/qpushbutton_test.py index 3b23e1b9c..859202bb4 100644 --- a/sources/pyside6/tests/QtWidgets/qpushbutton_test.py +++ b/sources/pyside6/tests/QtWidgets/qpushbutton_test.py @@ -37,7 +37,7 @@ init_test_paths(False) from helper.usesqapplication import UsesQApplication from PySide6.QtWidgets import QPushButton, QMenu, QWidget -from PySide6.QtCore import QTimer +from PySide6.QtCore import QTimer, Qt class MyWidget(QWidget): @@ -67,6 +67,7 @@ class QPushButtonTest(UsesQApplication): def testBoolinSignal(self): b = QPushButton() b.setCheckable(True) + b.setShortcut(Qt.Key_A) self._clicked = False b.toggled[bool].connect(self.buttonCb) b.toggle() |
