Every time I think I understand how to implement a tableview with a model...


In this case I have two things:

when I insert a row in the model I've implemented the insert in the model:

Qt Code:
  1. def insertRows(self, row, count):
  2. targetindex = self.createIndex(row, 0)
  3. self.beginInsertRows(targetindex, self.rowCount(),self.rowCount()+1)
  4. # copy last row data, except add a new StageState for all StageState columns
  5.  
  6. newrow = self.arraydata[self.rowCount()-1][:] # slice [:] clones the row
  7. # new uuid for this character
  8. newrow[0] = '{}'.format(uuid.uuid4())
  9. self.arraydata.append(newrow)
  10. self.endInsertRows()
  11. return True
To copy to clipboard, switch view to plain text mode 

This works and the table IS updated with the new row at the correct place in the table.
self.arraydata is a list...so I don't get why the new row isn't at the end of the table.
(probably my limited python-ness )

Also, to delete a row, I implemented:

Qt Code:
  1. def removeRows(self, row, count):
  2. targetindex =self.createIndex(row, 0)
  3. self.beginRemoveRows(targetindex, row, row-1)
  4. popped_item = self.arraydata.pop(targetindex.row())
  5. self.endRemoveRows()
  6. return True
To copy to clipboard, switch view to plain text mode 

This works fine for any row in the table, except the last row.
It does delete the last row, but, when I click on any other row after the delete:

QAccessibleTable::child: Invalid index at: 29 2
Cannot creat accessible child interface for object: QTableView(0x249a530, name = "table_cast") index: 123

In this particular run the table was 30 rows long and one was removed. I think that's the 29. I have no idea what index: 123 means...since there was/is only 30 rows...


Regards,
Mac