PyQt4 Move QTableWidget row with widgets

Posted by Guard on Stack Overflow See other posts from Stack Overflow or by Guard
Published on 2010-06-03T08:58:19Z Indexed on 2010/06/03 9:04 UTC
Read the original article Hit count: 351

Filed under:
|
|

I have the following method in my PyQt4 app. r2 is the number of row to move, and r1 is the position where it should be moved. To clarify: the table is filled with cellWidgets, not widgetItems.

def move_row(self, r1, r2):
    tt = self.tableWidget
    tt.insertRow(r1)
    for c in range(tt.columnCount()):
        tt.setCellWidget(r1, c, tt.cellWidget(r2 + 1, c))
    tt.removeRow(r2 + 1) # <--- ???

If I comment out the last line, it behaves as expected: the new row is inserted at position r1, it is filled with widgets from r2 (now it's r2+1), and the r2+1 row is empty. If I even hide this row, it behaves well, though it is not what I want (I have the rows numbered, and I don't want this hidden row to occupy the number). But if I remove the row, the widgets initially owned by it disappear. Looks like their ownership is taken on first placement, and is not changed after the move.

Any ideas?

© Stack Overflow or respective owner

Related posts about python

Related posts about pyqt