PyQt中向子控件分发消息问题
代码如下:
import sysfrom PyQt4 import QtGuifrom PyQt4 import QtCoreclass Children(QtGui.QFrame): def __init__(self, parent = None): QtGui.QFrame.__init__(self, parent) def keyPressEvent(self, event): print('keyPress in children') QtGui.QFrame.keyPressEvent(self, event) class Father(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) child = Children(self) self.setCentralWidget(child) def keyPressEvent(self, event): print('keyPress in Father') QtGui.QMainWindow.keyPressEvent(self, event) app = QtGui.QApplication(sys.argv)fa = Father()fa.show()app.exec_()