Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget drag and drop
Qt 6.11 is out! See what's new in the release blog

QTableWidget drag and drop

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marko_it
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      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(..).

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marko_it
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved