Mar-03-2021, 05:36 AM
(This post was last modified: Mar-03-2021, 05:36 AM by deanhystad.)
You could use WINDOW.tab_form.currentWidget() to get the selected widget (either a hardwareTab or softwareTab). You can use this to get hold of any of the parts. Once you have the parts you can get the text you need.
Subclassing enterNewHardware from hardwareTab does not do what you want. enterNewHardware() creates a new enterNewHardware object. This object has no visibility into your existing hardwareTab object. It has the same attirbute names, but the objects in the hardwareTab object are completely different than the enterNewHardware objects. The two things are similar types, but not the same thing. You and I are People, but I don't know how much change is in your pocket.
You could do something like this:
It might make more sense to make "enterNewHardware()" a method of hardwareTab. Or it might make more sense to make it a "glue" function that knows enough about hardwareTab and enough about the database to serve as an intermediary.
Subclassing enterNewHardware from hardwareTab does not do what you want. enterNewHardware() creates a new enterNewHardware object. This object has no visibility into your existing hardwareTab object. It has the same attirbute names, but the objects in the hardwareTab object are completely different than the enterNewHardware objects. The two things are similar types, but not the same thing. You and I are People, but I don't know how much change is in your pocket.
You could do something like this:
class mainWindow(QMainWindow): def __init__(self): super().__init__() self.tabForm = QTabWidget() self.tabForm.addTab(hardwareTab(), "HARDWARE") self.setCentralWidget(self.tabForm) class hardwareTab(QWidget): def __init__(self): super().__init__() self.snTextBox = QLineEdit() self.enButton = QPushButton("ENTER NEW HARDWARE") layout = QVBoxLayout(self) layout.addWidget(self.snTextBox) layout.addWidget(self.enButton) self.enButton.clicked.connect(lambda: enterNewHardware(self)) def enterNewHardware(hardware): serial_number = hardware.snTextBox.text() ... conn.commit() if __name__ == "__main__": APP = QApplication(sys.argv) WINDOW = mainWindow() WINDOW.show() sys.exit(APP.exec_())Here we pass the hardwareTab object as an argument to the enterNewHardware() function. This object contains the widgets you are looking for.
It might make more sense to make "enterNewHardware()" a method of hardwareTab. Or it might make more sense to make it a "glue" function that knows enough about hardwareTab and enough about the database to serve as an intermediary.