读书人

PyQt中向子控件分发消息有关问题

发布时间: 2012-02-06 15:52:45 作者: rapoo

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 很简单的哦 亲

读书人网 >perl python

热点推荐