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. Drag and drop between QTableView and QGraphicsView (from model to model)

Drag and drop between QTableView and QGraphicsView (from model to model)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.4k 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.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    I have a QTableView (its model is QStandardItemModel) and I have a QGraphicsView (its model is a QGraphicsScene). I'd like to copy/move an item (an icon with text) from the table into the graphics area.

    How can I solve this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You will need to implement it yourself. There is no feature in Qt that does all this automatically, but it certainly can be done (from experience, I have done it).

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        Yes, I know that I have to implement it myself.
        But I have no idea, how can I solve it.
        My main problem is with the model...

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          QGraphicsView forwards drag & drop events to the scene. "This section":/doc/qt-4.8/graphicsview.html#drag-and-drop in the documentation should get you started.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            What I have done till now:

            drag side:
            I have a subclassed QTableView. I reimplemented the mouseMoveEvent function. Here I assembled the mimedata and started the drag.
            This event is running good when I drag a row from the table.

            drop side:
            This is a subclassed QGraphicsView, here I have some pixmap on the scene (and on the view). I reimplemented the dragEnterEvent what is running good.

            But:
            I reimplemented the dropEvent too, but this event doesn't run at all...

            @
            void DisplayLayout::dropEvent(QDropEvent* event)
            {
            qDebug() << "dropEvent" ;
            }
            @

            Why?

            (And what is the different between event->acceptProposedAction(); and event->setAccepted(true); ?)

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

              Another "helpful wiki entry":https://qt-project.org/doc/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views on the subject.

              Make sure you have enabled drag & drop in both views, and that the mime data is accepted.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                broadpeak
                wrote on last edited by
                #7

                Thx the link, I've read this article.

                My mimedata seems to be good.
                I've set in the views the setDragEnabled(true) and setAcceptDrops(true);

                What I'd like to: select a row in the table (get the ID), and I pass this ID into the graphicsview, and added a pixmap with this ID.

                But I have no succes :(

                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