drmacro
2nd November 2017, 18:55
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:
def insertRows(self, row, count):
targetindex = self.createIndex(row, 0)
self.beginInsertRows(targetindex, self.rowCount(),self.rowCount()+1)
# copy last row data, except add a new StageState for all StageState columns
newrow = self.arraydata[self.rowCount()-1][:] # slice [:] clones the row
# new uuid for this character
newrow[0] = '{}'.format(uuid.uuid4())
self.arraydata.append(newrow)
self.endInsertRows()
return True
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 :p )
Also, to delete a row, I implemented:
def removeRows(self, row, count):
targetindex =self.createIndex(row, 0)
self.beginRemoveRows(targetindex, row, row-1)
popped_item = self.arraydata.pop(targetindex.row())
self.endRemoveRows()
return True
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...
:confused:
Regards,
Mac
:(
In this case I have two things:
when I insert a row in the model I've implemented the insert in the model:
def insertRows(self, row, count):
targetindex = self.createIndex(row, 0)
self.beginInsertRows(targetindex, self.rowCount(),self.rowCount()+1)
# copy last row data, except add a new StageState for all StageState columns
newrow = self.arraydata[self.rowCount()-1][:] # slice [:] clones the row
# new uuid for this character
newrow[0] = '{}'.format(uuid.uuid4())
self.arraydata.append(newrow)
self.endInsertRows()
return True
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 :p )
Also, to delete a row, I implemented:
def removeRows(self, row, count):
targetindex =self.createIndex(row, 0)
self.beginRemoveRows(targetindex, row, row-1)
popped_item = self.arraydata.pop(targetindex.row())
self.endRemoveRows()
return True
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...
:confused:
Regards,
Mac