擅长:python、mysql、java
<p>这对我有用,也应该和其他小部件一起工作。在</p>
<pre><code>import sys
from PyQt4 import QtCore, QtGui, Qt
from ChildWindow import ChildWindow
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
QtCore.QTimer.singleShot(500, self.showChildWindow)
self.textEdit = QtGui.QTextEdit(self)
self.textEdit.resize(100, 100)
def showChildWindow(self):
QtGui.QApplication.sendEvent(self.textEdit, QtGui.QKeyEvent(QtGui.QKeyEvent.KeyPress, QtCore.Qt.Key_A, QtCore.Qt.NoModifier, "hello"))
QtGui.QApplication.sendEvent(self.textEdit, QtGui.QKeyEvent(QtGui.QKeyEvent.KeyPress, QtCore.Qt.Key_Return, QtCore.Qt.NoModifier))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
</code></pre>