Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MVC Single Model Two Dialogs - with PyQt

Status
Not open for further replies.

JoeMicro

Technical User
Aug 24, 2007
76
CA
Hi, i am trying to use a single dataModel for two different forms in hopes that when the dataModel is changed in one form it will effect the other as well. but that doesnt work.

i built two forms:

Form_1: has two views set to a model class.
Form_2: has one view connected to the same model class.

if i change data on any view on Form_1 it changes it both view's however Form_2 doesn't change?
does any body have any suggestions of how to make to saparate forms which are connected to the same model, update when data is changed in one.

here is my code:
Python:
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_()

any help would be immensely appreciated.

Joe

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top