Please nominate your Qt Champions for 2021!

QTableWidget drag and drop

  • Hi all,

    I need to customize a drag and drop in a class that inherts QTableWidget.
    To do so, I have used the QTable´s API and overridden mousePressEvent and mouseMoveEvent handlers.
    I need to start the drag just normally, so I create the QDrag class´s object and populate it with mime data of the selected table´s items.
    Nevertheless, the following code gets me a null pointer when I try to generate mime data:

    @void PlacementEditorTable::mouseMoveEvent(QMouseEvent event)
    drag = new QDrag(this);

       QList<QTableWidgetItem *>  list = this->selectedItems(); // non empty list
        QMimeData* mime_data =  this->mimeData(list); // NULL !?



    Is this a bug, or am I doing something wrong?
    Could you help please. The version of QT is 4.7.

    Best Regards,


  • Have a look at "this": All the item view classes already support drag and drop, there is no need to reimplement mouseMoveEvent(..).

  • Hi I do need to override, as I need some custom behaviour of the drag and drop. I need to swap the elements inside a table using drag and drop...

    Still, why is mimeData() returning null if I provide a correct list? Is this bug known?

Log in to reply