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