Drag and Drop of QListView Items



  • Hi..
    I have a ListView and a Widget. In ListView i had added few items using QStandardItem. Now i want to Drag and Drop the ListView Items to the Widget . I can drag and drop my ListView Items inside the ListView by using

    @listView.setAcceptDrops(true);
    listView.setDragEnabled(true);
    listView.setDragDropMode(QAbstractItemView::InternalMove); @

    But i want to Drag and Drop the Items to the Widget. so i tried to override the following methods.

    @void dropEvent(QDropEvent *);
    void dragMoveEvent(QDragMoveEvent *);
    void dragEnterEvent(QDragEnterEvent *);
    void mousePressEvent(QMouseEvent *);
    void startDrag(Qt::DropActions supportedActions);@

    After trying this i can able to drag my items to the widget but i can't drop my items on the widget.. don't know where i did the mistake. please help me to solve this..

    Thanks & Regards...



  • There are some real good d&d-examples in the doc-area.
    I think there should be a solution to your problem.

    "examples-draganddrop":http://qt-project.org/doc/qt-4.8/examples-draganddrop.html

    I think the example DragableText will best fit.



  • Yeah its a very good example. Thanks for your reply. But the thing is, there they r using the QLabel, hence they can easily type cast it and get the position of the Label. but here am using a standard item model... i can type cast my standard item model but i can't get the posiiton. In order to get the position, i have to use a QModelIndex. Using QModelIndex also i can't get the indexAt(event->pos()). that is not working. . :( what should i do now... plz help me...!!!

    Thanks & Regards...



  • Same problem bothered me.


Log in to reply
 

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