我有两个表单,两个视图连接到同一个 dataModel 类,但是当我在一个表单上更改数据时,它不会在另一个表单上更改。
我试图在几个不同的对话框/表单上获取一个组合框,以便在底层数据从另一个对话框/表单更改时得到更新。
这是我的代码:
class Model(QStringListModel):
def __init__(self, parent=None):
super(Model, self).__init__(parent)
data = QStringList()
data << "one" << "two" << "three" << "four" << "five"
self.setStringList(data)
class Form_2(QDialog):
def __init__(self, parent=None):
super(Form_2, self).__init__(parent)
self.model = Model()
self.combo = QListView()
self.combo.setModel(self.model)
layout = QVBoxLayout()
layout.addWidget(self.combo)
self.setLayout(layout)
class Form_1(QDialog):
def __init__(self, parent=None):
super(Form_1, self).__init__(parent)
self.model = Model()
self.listView = QListView()
self.listView.setModel(self.model)
self.combo = QComboBox()
self.combo.setModel(self.model)
self.form2_button = QPushButton("Open Form_2")
layout = QVBoxLayout()
layout.addWidget(self.listView)
layout.addWidget(self.combo)
layout.addWidget(self.form2_button)
self.setLayout(layout)
self.connect(self.form2_button, SIGNAL("clicked()"), self.form_2)
def form_2(self):
self.ft = Form_2()
self.ft.show()
app = QApplication(sys.argv)
form = Form_1()
form.show()
app.exec_()