[Solved] QTableView (QTableWidget) removeRow removes several rows
I have this code:
self.connect(table, SIGNAL('cellPressed(int, int)'), self.deleteRowClicked)
def deleteRowClicked(self, row, column):
if column == 0:
table = self.sender()
So if the user clicks on the cell of the first column the row is removed.
The problem I have is that this code remove not only that row, also all rows behind it. :?
What I'm doing bad???
Hi and welcome to devnet,
Are you sure your slot is not called twice rather than removing two rows ?
Yes it is called, not twice, several times! , why???
Right now, I don't know. Did you check the row/col values ? Are you keeping the mouse down when pressing your mouse button ?
Tried to do it for several ways, in one table the event is called twice, by the other hand a similar table, the event is called like ten times.
Might be propagating to the next cell since you delete the one under the cursors (that's just an idea nothing more)
Personally, I wouldn't use cellPressed to delete a row, rather cellClicked or cellDoubleClicked.
I finally found the problem, the connect method was called each time a row is add to the TableWidget, so when the signal arrives the slot is called once per connect.
That's a classic :)
Most of the time connections like this one should be done in the widget's constructor
Still working wit QT designer so the constructor is changing frecuently. On the final version i will put it there all the connections.