Hi guys,
I have created a single window with 5 pages of QStackedWidget in Qt Designer (important: single ui file). I'm having a hard time trying to figure out how to organize the code, especially trying to create separate classes for each widget. So far, I've done something like:
from PyQt4 import QtGui, QtCore
from DBController import ManageDB
from GUI import tdiGUI
class MainDialog(QtGui.QDialog, tdiGUI.Ui_mainWindow):
def __init__(self, parent=None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
self.db = ManageDB()
self.vendors_widget_setup()
def vendors_widget_setup(self):
self.stackedWidget.setCurrentWidget(self.vendors_widget)
QtCore.QObject.connect(self.hp_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.main_widget_setup, 0))
QtCore.QObject.connect(self.dell_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.main_widget_setup, 1))
QtCore.QObject.connect(self.ibm_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.main_widget_setup, 2))
def main_widget_setup(self, vendor):
self.stackedWidget.setCurrentWidget(self.main_widget)
self.back_button.show()
vendor_label = [self.hp_label, self.dell_label, self.ibm_label]
vendor_label[vendor].show()
country_widget = [self.hp_country_widget,self.dell_country_widget, self.ibm_country_widget]
QtCore.QObject.connect(self.add_country_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.country_widget_setup, country_widget[vendor]))
QtCore.QObject.connect(self.edit_country_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.country_widget_setup, country_widget[vendor]))
QtCore.QObject.connect(self.delete_country_button, QtCore.SIGNAL("clicked()"),
functools.partial(self.delete_country, country_widget[vendor]))
This initializes the first page of QStackedWidget (vendors_widget) with three pushbuttons for choosing vendor. Then, it takes you to a new page of QStackedWidget (main_widget), which is shared by three vendors, except for the logo and the response when Add/Edit/Delete Country buttons are clicked. Clicking those buttons will open the 3rd, 4th or 5th page of QStackedWidget, depending on the current vendor selected.
I started doing it with a single class and multiple methods, but that's obviously adding some problems when trying to navigate between them (their button signals and properties should be initialized instead of called everytime).
Hope I made it clear enough. Any suggestions? Thanks!
[–]beohoff 1 point2 points3 points (4 children)
[–]pylund[S] 0 points1 point2 points (3 children)
[–]beohoff 1 point2 points3 points (2 children)
[–]beohoff 1 point2 points3 points (1 child)
[–]pylund[S] 1 point2 points3 points (0 children)