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)
    {
    ...
    QDrag
    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,

    Marko



  • Have a look at "this":https://qt-project.org/doc/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views. 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.