Answer the question
In order to leave comments, you need to log in
How to run a method in PyQt when a keyboard key is pressed?
There is a class, how to determine keystrokes in it, let's say (Ё) on the keyboard and run some method.
Here is part of the class code:
import sys
from wikides import *
from wikicore import *
from PyQt5 import QtCore, QtGui, QtWidgets
class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.path = os.path.dirname(__file__)
self.pathTemp = self.path +'/temp'
# Клик по кнопке.
self.ui.pushButton.clicked.connect(self.WikiGo)
def WikiGo(self):
cmd = recToText()
self.showText(cmd)
# ....... и т. д.
Answer the question
In order to leave comments, you need to log in
Ha, just went through this rake:
Add a method:
def keyPressEvent(self, e):
if e.key() in [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return]:
self.WikiGo()
else:
super(MyWindow, self).keyPressEvent(e)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question