PyQt6 Creating keyboard shortcuts
-
Hi, all,
I needed to convert my PyQt5 to PyQt6. I did not find yet a solution to define keyboard shortcuts.
In PyQt5 I have the following code:
self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self) self.shortcut_open.activated.connect(self.getFile)
I tried something like that in PyQt6, without success:
self.button_action = QAction("Your button", self) self.button_action.setStatusTip("This is your button") self.button_action.triggered.connect(self.onMyToolBarButtonClick) self.toolbar.addAction(self.button_action) self.button_action.setShortcut(QKeySequence("Ctrl+p"))
Do you have any suggestion about it?
-
@pedrovg said in PyQt6 Creating keyboard shortcuts:
I needed to convert my PyQt5 to PyQt6. I did not find yet a solution to define keyboard shortcuts.
In PyQt5 I have the following code:
self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self)
self.shortcut_open.activated.connect(self.getFile)I tried something like that in PyQt6, without success:
self.button_action = QAction("Your button", self)
self.button_action.setStatusTip("This is your button")
self.button_action.triggered.connect(self.onMyToolBarButtonClick)
self.toolbar.addAction(self.button_action)
self.button_action.setShortcut(QKeySequence("Ctrl+p"))Unfortunately, this does not work. The solution I found is to use the QShortcut class in PyQt6, like in PyQt5:
self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self) self.shortcut_open.activated.connect(self.getFile)