Python Forum
[PyQt] how to pass tablewidget object like argument for function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] how to pass tablewidget object like argument for function
#1
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"))
Reply


Messages In This Thread
how to pass tablewidget object like argument for function - by atlass218 - Feb-20-2020, 08:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how I can use the widgets as an argument of a function? pymn 9 2,353 Apr-26-2022, 09:23 PM
Last Post: deanhystad
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 5,170 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,266 Feb-09-2021, 06:10 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020