[Python] Permutate two rows inside QTableWidget

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a simple QTableWidget with a unique relevant column (the other one still empty for the moment). And I try to permute two rows.

    I’ve made this method to my table:

    def permuteRows(self, row1=0, row2=3):
    # saving the original contents
    widget1 = self.table.cellWidget(row1, 1)
    widget2 = self.table.cellWidget(row2, 1)

    # Suppression of the widgets
    self.table.removeCellWidget(row1, 1)
    self.table.removeCellWidget(row2, 1)

    # Re-injection of the widgets (in the oposite rows)
    self.table.setCellWidget(row1, 1, widget2)
    self.table.setCellWidget(row2, 1, widget1)


    But, when I run this method, I just get this error:

    [1] 3189684 segmentation fault python mnemos.py


    And nothing else.

    The problem only occur when I inject the second row. It happens as if it occur a circular refrence, however a remove it before.

    The question


    How to permute two rows of table? With this way or another way.

    Continue reading...

Compartilhe esta Página