PyQt中向子控件分发消息问题
代码如下:
- Python code
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_()
在一个MainWindow中添加了一个Frame,但是为什么按键消息只传到MainWindow中,而子控件Frame中收不到?
[解决办法]
没弄过,是不是就这么设计的啊,
你可以在父窗口接收到再发送给子控件。
[解决办法]
SetStrongFocus 很简单的哦 亲