Unsolved Move rows in a QTableWidget
-
Hello!!
I am trying to move rows in a QTableWidget. My idea is to have two buttons (up and down).
The procedure that I want is:
- Select a row. (for example row 2)
- Push a button (for example, button down)
- The table must swap the row 2 with row 3, because we want to move the row 2 down.
Is there any easy way to do this?
Thank you very much!!
-
Unfortunately Qt generic models do not implement
moveRows
. You have 2 choices:- save the data, remove the row, insert the row and re-set the data
- store temporary indexes in a user role and use
QSortFilterProxyModel
to sort it (requires switching to model+view and the change is not actually done in the original model)