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
#2
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?
Reply
#3
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"))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how I can use the widgets as an argument of a function? pymn 9 2,100 Apr-26-2022, 09:23 PM
Last Post: deanhystad
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,878 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,113 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