0

I am using the Qt designer to create an application. Into my code I generated a dataframe and I would like to display it (final results) in a QtableView or QtableWidget. I created a few screens in QT designer and made the conection in main code with variables using uic. On one of these screens I created a tableWidget with columns and rows (9 x 8) and named them, same size than dataframe. I have found some examples here and other forums neverthless It seens too complicated (create a model, etc).

I got to fill only one cell using tb.tableWidget.item(0, 0).setText(str(round(df['xi'][0],2))), but when I tried to apply a 'for' It didn't work.

tb.tableWidget.item(0, 0).setText(str(round(df['xi'][0],2)))

#tb.tableWidget.item(0, i).setText(str(round(df['xi'][i],2))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'NoneType' object has no attribute 'setText'.

musicamante
  • 41,230
  • 6
  • 33
  • 58
  • By default QTableWidget doesn't have real items, unless some data has been set. You need to create each QTableWidgetItem (if it doesn't exist, which is what happens when `item()` returns `None`) with the data you want to display and then call `setItem()`. – musicamante Aug 18 '23 at 17:22

0 Answers0