Python Forum

Full Version: how to pass tablewidget object like argument for function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi;
I have many object of QTabelwidget (tablewidget1,tablewidgte2,tablewidget3, ...)
I created a function for each tablewidget, therefore I have a number of functions equal to the number of tablewidget.

def intialiser_tableWidget(self):
    self.tableWidget.clear() # effacer contenu
    self.tableWidget.setHorizontalHeaderItem(0, QTableWidgetItem("date"))
    self.tableWidget.setHorizontalHeaderItem(1, QTableWidgetItem("hour"))
    self.tableWidget.setHorizontalHeaderItem(2, QTableWidgetItem("Mo1"))
    self.tableWidget.setHorizontalHeaderItem(3, QTableWidgetItem("Mon2"))
this function is activated by clicking on a radiobutton.

I wonder how to create a single function which will replace all these functions by changing only the argument which will coincide with the name of the tablewidget

I try this function instead of the initial function but doesn't work like I want

arg=QTableWidget
def intialiser_tableWidget_correction(self,arg):      
    self.arg.clear()
    self.arg.setHorizontalHeaderItem(0, QTableWidgetItem("date"))
    self.arg.setHorizontalHeaderItem(1, QTableWidgetItem("hour"))
    self.arg.setHorizontalHeaderItem(2, QTableWidgetItem("Mon1"))
    self.arg.setHorizontalHeaderItem(3, QTableWidgetItem("Mon2"))
Wow this looks similar ;) So what is the value of the Arguments you are passing in? Is it (0, 1, 2, 3) or ('date', 'hour', 'Mo1', 'Mon2') or both or something else that you have out even hinted at?
a solution of this problem is to do like that :


def __init__(self,parent=None) :
        super(MainApp,self).__init__(parent)
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.win_UI()
    ################################
        arg=QTableWidget()

def intialiser_tableWidget_correction(self,arg):      
    arg.clear()
    arg.setHorizontalHeaderItem(0, QTableWidgetItem("date"))
    arg.setHorizontalHeaderItem(1, QTableWidgetItem("hour"))
    arg.setHorizontalHeaderItem(2, QTableWidgetItem("Mon1"))
    arg.setHorizontalHeaderItem(3, QTableWidgetItem("Mon2"))