我在 PyQt 中的 2 个窗口之间的通信有问题。
主窗口 = UI_Form(MyForm 类) 附加窗口 = UI_Employee(Employee 类)
当我单击 AddTextButton (Ui_Employee) 时,我想在 LineTextEdit (UI_Form) 中设置文本这是我的代码。
import sys
from PyQt4 import QtCore, QtGui
from Form import Ui_Form
from Window import Ui_Employee
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.AddButton,QtCore.SIGNAL("clicked()"), self.add)
def add(self):
self.Employee = Employee(self)
self.Employee.show()
class Employee(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_Employee()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.AddRowButton,QtCore.SIGNAL('clicked()'), self.addText)
def addText(self):
self.Form = MyForm()
self.Form.ui.textEdit.setText('someText')
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
我在方法 addText 中遇到了问题。第一行和第二行被忽略。我不知道为什么。