Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Drag a copy of an item to Droparea
Forum Updated to NodeBB v4.3 + New Features

Drag a copy of an item to Droparea

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 5.3k 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.
  • S Offline
    S Offline
    stevenhurd
    wrote on last edited by
    #1

    I've been attempting to implement something similar to the QtQuick example drag and drop:
    http://doc-snapshot.qt-project.org/5.0/qtquick/quick-draganddrop.html

    It seems quite straightforward to drag items from a list to a Droparea and the example is almost what I want to do. In my case, however, I need to keep the original list intact (i.e. make a copy of the original list item to put in the Droparea). I'm assuming this line in DragTile.qml:

    @
    onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
    @

    becomes something more like:

    @
    onReleased: {
    if(tile.Drag.target !== null ) { cppModel.copyItem(tile.Drag.target) }
    }
    @

    Is this reasonable?

    Also, when in the process of dragging, can I leave the list item in place and drag some sort of graphical replacement for it? If so, how would I do this?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      osfesa
      wrote on last edited by
      #2

      It's C.

      Is somethink like this:

      @ onReleased: {
      if(tile.Drag.target !== null ) { cppModel.copyItem(tile.Drag.target) }
      }
      else
      {
      root;
      }@

      If root makes something. If not, is like you say.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stevenhurd
        wrote on last edited by
        #3

        So that works for adding the item to the C++ model. I still am not sure how to drag a "copy" of the object to add to the model.

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

          OK, so I found an example that does essentially what I want:

          http://qt-project.org/doc/qt-4.8/declarative-toys-dynamicscene.html (Specifically the dragging and dropping of scene elements)

          The only real issue is that it's Qt 4.8 and it's not especially easy to implement that same behavior in my application because I'm actually dragging it to a DropArea that's a view which will rearrange items rather than simply allowing the item to drop in an arbitrary location.

          It seems like this is a pretty basic case that should be handled by QML in Qt 5.0. Is this just not a case that is meant to be handled by the base QML elements?

          Any guidance would be appreciated.

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

            @stevenhurd Hello,
            I'm facing the same issue here. Have you found any way to drag a copy through Drag and DropArea mechanism.
            Any help will be appreciated.
            Thank you.

            I don't have endpoint, I just have Checkpoints.

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

              Hmm, yeah, I actually did get it working but that was a long time ago and I haven't looked at the code much lately. You're welcome to browse through it though to see what you can find: "https://github.com/stevenchurd/EvalWriter/tree/beta/code/gui/qml":https://github.com/stevenchurd/EvalWriter/tree/beta/code/gui/qml

              I ended up doing it with the help of javascript if I remember correctly. Maybe start with this and see if it helps: "https://github.com/stevenchurd/EvalWriter/blob/beta/code/gui/qml/criteriaItemRowCreation.js":https://github.com/stevenchurd/EvalWriter/blob/beta/code/gui/qml/criteriaItemRowCreation.js

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Muhammad
                wrote on last edited by
                #7

                Thank you I will take a look and try to figure it out.
                Thank you again.

                I don't have endpoint, I just have Checkpoints.

                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