Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.3.1
-
None
Description
The problem is stated in the title.
Expected behavior: A shortcut with context Qt.WidgetShortcut or Qt.WidgetWithChildrenShortcut would be active when it's parent (/a child of it's parent) receives focus. Instead both shortcuts do nothing regardless of the focus.
from PySide6.QtCore import Qt from PySide6.QtGui import QKeySequence, QShortcut from PySide6.QtWidgets import QApplication, QHBoxLayout, QLineEdit, QTextEdit, QVBoxLayout, QWidget class Child(QWidget): def __init__(self, parent): super().__init__(parent) layout = QVBoxLayout(self) layout.addWidget(QLineEdit(self)) QShortcut(QKeySequence('F1'), self, self.handle_shortcut, Qt.WidgetWithChildrenShortcut) def handle_shortcut(self): print('At child shortcut') class Window(QWidget): def __init__(self): super().__init__() self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.addWidget(QTextEdit(self)) self.horizontalLayout.addWidget(Child(self)) QShortcut(QKeySequence('f1'), self, self.handle_shortcut, Qt.WidgetShortcut) def handle_shortcut(self): print('At window shortcut') app = QApplication() window = Window() window.show() app.exec()