Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105296

Adding a shortcut with the same key to a child disables both shortcuts

XMLWordPrintable

      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()
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            srutledg Shawn Rutledge
            petko10 Petko Ditchev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes