I want to improve my code but currently have not much idea how. So I used Qt Designer and created a main window plus 3 dialogs which can be opened from main window. Converted .ui files to .py files and created the MainWindow class which manages all. Everything works fine, but for me this looks wrong:
class MainWindow(QMainWindow, Ui_MainWindow):
# init and else
[...]
def open_add_dialog(self):
self.dialog = AddDialog()
self.dialog.show()
def open_edit_dialog(self):
self.dialog = EditDialog()
self.dialog.show()
def open_about_dialog(self):
self.dialog = AboutDialog()
self.dialog.show()
def assign_widgets(self):
self.actionAdd.triggered.connect(self.open_add_dialog)
self.actionEdit.triggered.connect(self.open_edit_dialog)
self.actionAbout.triggered.connect(self.open_about_dialog)
Code is simplified.. So as you see I've 3 almost equal methods. So the question comes to my mind is it possible to merge all into one? What I want is something like this:
def open_dialog(self):
sender = self.sender()
sender.show()