I'm using PYQT5 and trying to loop though the rows in my table to retrieve the values in cells adding them to a list. Below is one of the many versions of the code I've written.
def grouping(self):
nrows = self.Table.rowCount()
group = []
for row in range(0,nrows):
item = self.Table.item(row, 2)
item_text = item.text()
group.append(item)
print(group)
def grouping(self):
nrows = self.Table.rowCount()
group = []
for row in range(0,nrows):
item = self.Table.item(row, 2)
item_text = item.text()
group.append(item)
print(group)
To copy to clipboard, switch view to plain text mode
If I don't use the "item_text = item.text()" line my list only contains the qtablewidgetitem objects. If I try to use the "item_text = item.text()" line or even add ".text()" to the item= line I get an error saying "AttributeError: 'NoneType' object has no attribute 'text'". Any help would be greatly appreciated.
Added after 13 minutes:
I should have also mentioned I'm setting up the table using the setItem function. The items are numbers defaulted as 1, that the user can edit if they wish to regroup the rows.
Bookmarks