0
我有一個現有的PyQt代碼:添加keyPressEvent到PyQt的
class MainWindow(QMainWindow, WindowMixin):
def __init__(self, filename=None):
super(MainWindow, self).__init__()
self.setWindowTitle(__appname__)
...
def resizeEvent(self, event):
def queueEvent(self, event):
我加了keyPressEvent:
def keyPressEvent(self, event):
print "pressed"
事實證明,它只能接受當一些小部件我輸入文本中的事件QMainWindow的。當圖片具有焦點時,它不會生成按鍵事件。我該如何解決這個問題?
文檔中提到了一些關於調用setFocusPolicy()來接受對窗口小部件的焦點並開始在窗口小部件上接收keyPress的信息。 – Marco