If you removeRow() multiple lines, you may run into some difficulties using removeRow() . This works with row indexes, so you need to delete rows from bottom to top so that row indices do not move when they are deleted. This is how I did it in PyQt, I donβt know C ++, but I think it is very similar:
rows = set() for index in self.table.selectedIndexes(): rows.add(index.row()) for row in sorted(rows, reverse=True): self.table.removeRow(row)
Works great for me! However, one thing you should know: in my case, this function is called when the user clicks on a specific cell (the button has an βXβ on it). Unfortunately, when they click on this button, it deselects the line, which then prevents it from being deleted. To fix this, I just grabbed the sender line and added it to the "remove_list" at the very beginning, before the "for loop". It looks like this:
remove_list.append(self.table.indexAt(self.sender().pos()).row())
source share