I am developping a PyQt5 gui. I try to implement a push button that would be pushed when I hit a key on my keyboard. Let say 'K'. I have tried this but it is not working. Any thoughts?
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout,QTabWidget, QFileDialog, QShortcut
from PyQt5.QtGui import QIcon, QPixmap, QKeySequence
from PyQt5 import QtCore, QtGui, QtWidgets, uic
Ui_TabWidget, QtBaseClass = uic.loadUiType(qtcreator_file)
class TabWidget(QTabWidget, Ui_TabWidget):
def __init__(self):
QtWidgets.QTabWidget.__init__(self)
Ui_TabWidget.__init__(self)
self.setupUi(self)
self.pushButtonGood.clicked.connect(lambda : self.writeOutliers(False))
self.pushButtonOutliers.clicked.connect(lambda : self.writeOutliers(True))
self.shortcut_open = QShortcut(QKeySequence('K'), self)
self.shortcut_open.activated.connect(lambda : self.writeOutliers(True))
from PyQt5.QtGui import QIcon, QPixmap, QKeySequence
from PyQt5 import QtCore, QtGui, QtWidgets, uic
Ui_TabWidget, QtBaseClass = uic.loadUiType(qtcreator_file)
class TabWidget(QTabWidget, Ui_TabWidget):
def __init__(self):
QtWidgets.QTabWidget.__init__(self)
Ui_TabWidget.__init__(self)
self.setupUi(self)
self.pushButtonGood.clicked.connect(lambda : self.writeOutliers(False))
self.pushButtonOutliers.clicked.connect(lambda : self.writeOutliers(True))
self.pushButtonGood.clicked.connect(self.setFocus)
self.setFocus
get the keyboard focus elsewhere that edittext at the first click on pushButtonGood
.
Then define the key shortcut of the buttons in the QTdesigner with the "Editeur de Propriétés".
Do a complexe shortcut 'ctrl+K'