Important: Please read the Qt Code of Conduct -

[Solved] Dragging from a QTableView to a QTreeView - order of events

  • I'm trying to drag from a QTableView to a QTreeView. My QTableView is called "partsview" and is descended from a QTableView. The relevant bits of the header are:

    @class partsiew : public QTableView
    explicit partsview(QWidget *parent = 0);
    QStringList mimeTypes() const;
    QMimeData *mimeData(const QModelIndexList &indexes) const;

    I have also added the following into the constructor of "partsview":


    When I attempt to drag an item the cursor changes appropriately, I can drop onto the QTreeView and I get a dropMimeData event is fired on the treeview.

    What I'm finding is that the two methods mimeTypes() and mimeData() are not called and the row and column values in the dropMimeData() event are both -1.

    o What order are the events/methods called? Should I get a call to mimeData() before I get a dropMimeData() event? (I'm wodering if this call only happens when a successful drop occurs).

    o Have I declared the mimeTypes() and mimeData() events/methods correctly so that they will be called at appropriate times?

    Any other pointers appreciated.

    Thank you,


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Because these two methods don't belong to QTableView. You can find them in the QTable/List/TreeWidget classes but they are a special case. With the View version of the classes, you need to implement them in your model. That will also allow you to change the view and still be able to do drag and drop without having to subclass the views.

  • Ahhh! Gotcha.

    Thank you.


  • Lifetime Qt Champion

    You're welcome !

    Since you have your model working now, please update the thread title prepending [solved] so other forum users my know a solution has been found :)

Log in to reply