Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Want to move a entire column in QtableWidget from Ist to Second position..



  • Hi All,
    I want to know ...how to move one of the column in TableWidget from Position 1 to position 2 using mouse and vice versa..

    I tried with the following function , but it was not working ..

    @tableWidget.setDragDropOverwriteMode(true);
    tableWidget.setDragEnabled(true);
    tableWidget.setDragDropMode(QAbstractItemView::InternalMove);
    tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows);@



  • This should do the trick:

    @
    tableWidget.horizontalHeader()->setMovable(true);
    tableWidget.verticalHeader()->setMovable(true);
    @

    It enables moving of both columns and rows. Leave out the last line if you only need it for columns.



  • Wow...Its wounderful.. Thanks a lot for your help..



  • Hi!

    I have a similar situation and I'm using the same method that you mentioned:
    @tableWidget.horizontalHeader()->setMovable(true);@

    In fact, I can move the header's cell of every column of the table using the mouse, the problem is that the cells below are not moving along with that column. So I only can move the header's cells, not the whole columns (which is my requirement).

    Any hint? Thanks.


Log in to reply