hi;
instead of creating a function for each tablewidget to initialize it, I would like to create a function in a class then I call this function in another class, making it assign as parameter the name of the tablewidgte to initialize :
Here is a sample of the code :
instead of creating a function for each tablewidget to initialize it, I would like to create a function in a class then I call this function in another class, making it assign as parameter the name of the tablewidgte to initialize :
Here is a sample of the code :
#!/usr/bin/python3 # -*- coding: utf-8 -*- from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * class prototype(): def __init__() : tablewidget=QTableWidget #function to initialize tablewidgte : def initialiser_tablewidget(self,tableWidget): self.tableWidget.clear() # effacer contenu self.tableWidget.setHorizontalHeaderItem(0, QTableWidgetItem("date")) self.tableWidget.setHorizontalHeaderItem(1, QTableWidgetItem("hour")) self.tableWidget.setHorizontalHeaderItem(2, QTableWidgetItem("Monitor1")) self.tableWidget.setHorizontalHeaderItem(3, QTableWidgetItem("Monitor2")) class MainApp(QMainWindow) : def __init__(self,parent=None) : super(MainApp,self).__init__(parent) QMainWindow.__init__(self) self.win_UI() self.prototype= prototype() def win_UI(self): self.setWindowTitle("ddm corrector") self.setGeometry(10,40,1140,653) #initialize tablewidgte_1 prototype.intialiser_tableWidget(tablewidgte_1) #initialize tablewidgte_2 prototype.intialiser_tableWidget(tablewidgte_2) def main(): app=QApplication(sys.argv) win=MainApp() win.show() app.exec_()# infinite loop if __name__=='__main__' : main()