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. Icon list tree view thing with drag and drop functions
Forum Update on Monday, May 27th 2025

Icon list tree view thing with drag and drop functions

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.8k Views
  • 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.
  • K Offline
    K Offline
    kcuzner
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      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);@

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

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          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 :)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Macro
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              Thats Great :)

              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