I have searched and not found an answer that works. That may be because I still don't get the tableview --> model connection...

I have a QTableView and it's associated model and the model data starts out empty.

At some point the data is changed (in this case the data starts out empty and is added to) (I can see the data in the model has changed in the debugger)

But, the table view doesn't update.

The code that does the update:
Qt Code:
  1. self.tablemodel.setData(self.tablemodel.rowCount(None), newitemindex,0)
  2. self.tableView_ControlsInStrip.resizeColumnsToContents()
  3. self.tableView_ControlsInStrip.selectRow(0)
To copy to clipboard, switch view to plain text mode 

The table model looks like this:
Qt Code:
  1. class MyTableModel(QtCore.QAbstractTableModel):
  2. def __init__(self, datain, headerdata, parent=None):
  3. """
  4. Args:
  5. datain: a list of lists\n
  6. headerdata: a list of strings
  7. """
  8. QtCore.QAbstractTableModel.__init__(self, parent)
  9. self.arraydata = datain
  10. self.headerdata = headerdata
  11.  
  12. def rowCount(self, parent):
  13. return len(self.arraydata)
  14.  
  15. def columnCount(self, parent):
  16. if len(self.arraydata) > 0:
  17. return len(self.arraydata[0])
  18. return 0
  19.  
  20. def data(self, index, role):
  21. if not index.isValid():
  22. return QVariant()
  23. # elif role == Qt.BackgroundColorRole:
  24. # #print (self.arraydata[index.row()][7])
  25. # if self.arraydata[index.row()][7] == 'Stage':
  26. # return QBrush(Qt.blue)
  27. # elif self.arraydata[index.row()][7] == 'Sound':
  28. # return QBrush(Qt.yellow)
  29. # elif self.arraydata[index.row()][7] == 'Light':
  30. # return QBrush(Qt.darkGreen)
  31. # elif self.arraydata[index.row()][7] == 'Mixer':
  32. # return QBrush(Qt.darkYellow)
  33. # else:
  34. # return QBrush(Qt.darkMagenta)
  35. #
  36. elif role != QtCore.Qt.DisplayRole:
  37. return QtCore.QVariant()
  38. return QtCore.QVariant(self.arraydata[index.row()][index.column()])
  39.  
  40. def setData(self, index, value, role):
  41. self.arraydata.extend([supportedcontroltypes[index]])
  42. self.dataChanged.emit(self.createIndex(0,0),
  43. self.createIndex(self.rowCount(None),self.columnCount(None)))
  44.  
  45. def headerData(self, col, orientation, role):
  46. if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
  47. return QtCore.QVariant(self.headerdata[col])
  48. return QtCore.QVariant()
To copy to clipboard, switch view to plain text mode