Icon list tree view thing with drag and drop functions



  • This is a rather complicated UI element, but I was wondering how this could be done. I am building a designer program which allows connection of elements together visually. I want something like what is shown below where there is an organized list of items which are shown by icon and then one can click on one of the icons in the list and then drag it over to the designer widget. So far what I have is a treeview inside a dock widget and the treeview is meant to display the items (which are hierarchical).

    !http://i.troll.ws/3675c31b.png(toolbar window drag and drop)!

    As an option I can get rid of the icon list idea and use a tree with text instead. However, the ability to drag from the list view over to the designer widget is a must.

    Does anyone know how to get this effect or do drag and drop in general with Qt?

    Also, while I am not new to programming within frameworks, I recently switched from GTK to Qt because it offered more than just a GUI framework with the cross-platform-ability in relation to threading and other things like that.



  • Hi,

    You can look in "Drag and Drop Puzzle Example":http://qt-project.org/doc/qt-4.8/draganddrop-puzzle.html and "Draggable Icons Example":http://qt-project.org/doc/qt-4.8/draganddrop-draggableicons.html that gives good information and implementation of drag and drop ,
    You need to override the following methods based on your requirement

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



  • Hi Sam,

    As u mentioned above i tried in that way. But it failed.. :( Don't know where i went wrong... I can't able to set the model index for the Items...
    In startDrag(), i tried it like this,

    @void ListView::startDrag(Qt:: DropActions supportedActiopn)
    {
    QByteArray array;
    QDataStream dataStream;
    QPoint offPoint;

    QStandardItem stdItem = static_cast<QStandardItem>(childAt(offPoint));
    daraStream << offPoint;

    QMimeData *mimeData = new QMimeData;
    mimeData->setData("application/x-draganddropitemdata");

    QDrag * drag = new QDrag(this);
    drag->setMimeData(mimeData);

    QModelIndex index = indexAt(offPoint ) //here i cant set the indexAt() ....@

    How to set the ModelIndex for the Item. Can u please elaborate it.. Hope it will b helpful...

    Thanks and Regards...



  • I did an example on the same long back. You can download the code "from here":http://www.mediafire.com/?cfaxqf564afvajp. Its just for test purpose, you can make changes as per your requirement :)



  • Thanks for your Reply Sam, I had Solved that issue by myself... :-)



  • Thats Great :)


Log in to reply
 

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