简体   繁体   中英

PyQt4 Move QTableWidget row with widgets

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?

我最终结束了小部件值的复制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM