I understand that the cellDoubleClicked method passes the row and the column to a specified function, but how can I send additional information as function arguments? For example the list the table was filled with.
if I have the following fuction (with functools.partial imported):
[CODE lang="python" title="Make Table Function"]
def makeTable(self, dataSet, layout):
cols = len(dataSet[0]) #columns
rows = len(dataSet) #rows
table = qtw.QTableWidget()
table.setRowCount(rows)
table.setColumnCount(cols)
for i in range(len(dataSet)):
for j in range(len(dataSet)):
table.setItem(i,j, QTableWidgetItem(dataSet[j]))
table.cellDoubleClicked.connect(partial(self.cellClick, i, j, dataSet))
layout.addWidget(table)
[/CODE]
The Line
always ends up passing the last iteration of i and j.
If I omit them, and send them a function like this for example:
[CODE lang="python" title="Example cell click function"] def cellClick(self, r, c, dataSet):
print('here: ', r, ' ', c, ' ', dataSet[r][c], '\n', dataSet)
[/CODE]
ends up with a "TypeError: 'int' object is not subscriptable" error.
Is there a way I can send the row and column of a cell double clicked, and the associated data set along with it?
if I have the following fuction (with functools.partial imported):
[CODE lang="python" title="Make Table Function"]
def makeTable(self, dataSet, layout):
cols = len(dataSet[0]) #columns
rows = len(dataSet) #rows
table = qtw.QTableWidget()
table.setRowCount(rows)
table.setColumnCount(cols)
for i in range(len(dataSet)):
for j in range(len(dataSet)):
table.setItem(i,j, QTableWidgetItem(dataSet[j]))
table.cellDoubleClicked.connect(partial(self.cellClick, i, j, dataSet))
layout.addWidget(table)
[/CODE]
The Line
Code:
table.cellDoubleClicked.connect(partial(self.cellClick, i, j, dataSet))
If I omit them, and send them a function like this for example:
[CODE lang="python" title="Example cell click function"] def cellClick(self, r, c, dataSet):
print('here: ', r, ' ', c, ' ', dataSet[r][c], '\n', dataSet)
[/CODE]
ends up with a "TypeError: 'int' object is not subscriptable" error.
Is there a way I can send the row and column of a cell double clicked, and the associated data set along with it?