×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

MVC Single Model Two Dialogs - with PyQt

MVC Single Model Two Dialogs - with PyQt

MVC Single Model Two Dialogs - with PyQt

(OP)
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:

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close