tags:

views:

38

answers:

1

I have a QtGui.QTableWidgetItem that I added to a table by the createRow function below:

def createRow(self, listA):
    rowNum = self.table.rowCount()
    self.table.insertRow(rowNum)
    i = 0
    for val in listA:
        self.table.setItem(rowNum, i, QtGui.QTableWidgetItem(val))
        i += 1

Now I have a thread that will update the row values periodically. The function called by the thread is the following:

def updateRow(self, listB):
    row = 0
    numRows = self.table.rowCount()
    i = 0
    while i < numRows:

        if listB[0] == self.table.item(i,0):
            row = i
        i+=1
    j = 0
    for val in listB:
        self.table.setItem(row, j, QtGui.QTableWidgetItem(val))
        j += 1

However, this is not working, because listB[0] is a string and self.table.item(i,0) is a QTableWidgetItem. Anyone know how I could solve this?

In the end, all I want is to update the row for the items that match the first item in the list this function takes as an input (listB).

+3  A: 

Use QTableWidgetItem.text(self) (i.e.: self.table.item(i,0).text()) to get the contents of a cell/QTableWidgetItem.

delnan