1

My class MainWindow(QMainWindow) for PyQt4 GUI has grown now and I want to split it somehow. The problem is that all numerous functions handling signals are very interconnected and influence other functions of the class. Is there any way to split it into several classes / files? Maybe separating all signals into one class? I don't really understand how to do that technically... I've also heard that there is some restriction from Qt (or PyQt) for multiple inheritance, which could solve the problem I guess (again, not obvious for me how exactly).

Just as an idea how it looks now (very very simplified, of course):

calss MainWindow(QMainWindow):
   ...
   def f1(self):
      if self.a1 == '...':
       ...
   def f2(self):
      if self.a2 == '...':
       ...
   def update(self):
      self.f3()
      self.f4()
      self.lineEdit.setText(self.a3)
      ...
   ...
   def on_radioButton_toggled(self):
      if self.radioButton.isChecked():
         self.a1 = '...'
   def on_comboBox_currentIndexChanged(self):
      if self.checkBox.isChecked():
         self.a2 = '...'
         self.f1()
      else:
         self.f2()
      self.update()
   ...

1 Answer 1

1

In my application I did it like this, there's the main window which contains child widgets (frames and stuff...), the main window does basically two things: initialize its children and connect the signals between them. Like this you have a hierarchy of views which is much simpler to handle that one big thing.

I think there isn't a painless move from your program to a more hierarchical one, I could say: you should have though of that earlier, but I don't. =P To design the main window and its children QTdesigner comes in very handy.

And yes, AFAIK a class should not inherit form more than one PyQt class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.