Python Forum
[PyQt] how to pass tablewidget object like argument for function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] how to pass tablewidget object like argument for function (/thread-24586.html)



how to pass tablewidget object like argument for function - atlass218 - Feb-20-2020

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"))



RE: how to pass tablewidget object like argument for function - Denni - Feb-21-2020

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?


RE: how to pass tablewidget object like argument for function - atlass218 - Mar-02-2020

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"))