Keyboard Shortcut for QPushButton
-
How i implement a shortcut for a QPushButton?
I know the menmonic method : "&f" ---> "f" is the name of the QPushButton
but if i have two QPushButton with name "f", how do i do? ....i would like two distinct shortcut.
@
shortAction= QAction(self)
shortAction.setShortcuts(QKeySequence(Qt.Key_F))
Buttons.addAction(shortAction)
@this code doesn't work!! Why?
-
Hi and welcome to devnet,
Because adding an action to a widget doesn't connect it automatically to any slot.
You have to connect it to e.g. the QPushButton::click slot
Hope it helps
-
Like this?
@
shortAction= QAction(self)
shortAction.setShortcuts(QKeySequence(Qt.Key_F))
Buttons.addAction(shortAction)
Button.clicked.connect(self.code)
@ -
You're still not connecting shortAction