⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Need to swap row in a QTableWidget

  • Hi,

    I have some problems with the QTableWidget, I can take an Item with takeItem() method, but not for a widget.
    There is only cellWidget(). The problem is when I use setCellWidget(), I erase the old widget even if I take it using cellWidget().

    I think, the QTableWidget erases the object and I only can have the address so the object is distroyed.

    So if I copy a Widget in an other, the other is erased so I can't swap row.

    My question is, do you have any idea to swap rows ?
    I use it because I have "up" and "down" buttons to move the rows.

    Thank you.
    Best regards.

    Sorry for my english, it's not my native language.

  • You need get model instance for your QTableWidget with method model().
    It has type QAbstractItemModel, see documentation of this class, it has methods for removing/inserting rows/columns.

  • Thanks a lot, I use you model function to take the model, and I sort a column in this model. So the column represent the index and I just need to swap the index value in column and I use sort function.

Log in to reply