Search code examples
pythonqtpyqtqtablewidgetqtablewidgetitem

PyQt5 QTableItem.setText() doenst do anything


I created my ui with Designer and converted it python code using pyuic5.

pyuic5 creates a QtableWidget instance which is called schedule, but doesnt init the cells so i inited them with:

for i in range(0,70):
            item = QtWidgets.QTableWidgetItem()
            self.schedule.setItem(i%14,math.floor(i/14),item)

And when i try to call setText() on them nothing happens. I check the internal value with text() right after I call setText() and it appears to be working fine but ui doesnt change.

for i in range(0,70):
            self.ui.schedule.itemAt(i%14,math.floor(i/14)).setText(timeSlots[i])
            print(self.ui.schedule.itemAt(i%14,math.floor(i/14)).text())

I thought about setting dimensions on QTableWidgetItem objects but i couldnt. It looks like they dont have a setGeometry() member.

I am running PyQt5 on Python2.7


Solution

  • Used .item() func instead of .itemAt() and it works.