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 and Drop in separate windows
QtWS25 Last Chance

Drag and Drop in separate windows

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

    I'm trying to do drag and drop between different windows. Code drag the same as in еxample externaldraganddrop. Problem: If after dragging one element from window to window to try to drag the other is dragged back first element. If before the next mouse click drag to make it dragged the item. What could I miss that?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It's not really clear. Could you show an example of what is happening ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Sorry for my english. :)

        Code and video with bug:

        @
        import QtQuick 2.2
        import QtQuick.Window 2.0

        Window {

        ListView {
            id: list
            anchors.fill: parent
        
            model: 5
        
            delegate: Rectangle {
                width: list.width
                height: 30
                border.color: "black"
                border.width: 1
        
                Text {
                    anchors.fill: parent
                    text: index
                }
        
                Item {
                    id: draggable
                    anchors.fill: parent
                    Drag.active: mouseArea.drag.active
                    Drag.hotSpot.x: 0
                    Drag.hotSpot.y: 0
                    Drag.mimeData: { "mediaItem": index }
                    Drag.dragType: Drag.Automatic
                    Drag.onDragStarted: {
                    }
                    Drag.onDragFinished: {
                    }
                }
        
                MouseArea {
                    id: mouseArea
                    anchors.fill: parent
        
                    drag.target: draggable
                }
            }
        }
        
        Window {
            visible: true
        
            Text {
                id:text
                anchors.fill: parent
            }
        
            DropArea {
                anchors.fill: parent
        
                keys: ["mediaItem"]
        
                onDropped: {
                    text.text += drop.source.mimeData["mediaItem"]
                    drop.acceptProposedAction()
                }
            }
        }
        

        }
        @

        "Video":http://youtu.be/8XFeAA_ry14

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have the same effect if you use the same code as the documentation ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shkryab
            wrote on last edited by
            #5

            The code above is the same as in the "example from the documentation":http://qt-project.org/doc/qt-5/qtquick-externaldraganddrop-example.html but with a few changes.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That's why I asked you to run it unmodified so as to see whether you have the same strange behavior.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shkryab
                wrote on last edited by
                #7

                Yes exactly. Such a behavior between two separate windows of the same application only. I tried to run unchanged code sample in two windows as a two different applications and as an one.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I'm not sure I'm understanding you correctly. Are you saying that with the code from the example, you get the same behavior you are currently getting with your original software ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shkryab
                    wrote on last edited by
                    #9

                    Yes. It's the same behavior all the time with two separate windows of the same application.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Sounds like this could be a bug. Have a look at the "bug report system":http://bugreports.qt-project.org to see if it's something known. If not please consider opening a new report providing a minimal compilable example that reproduce the behavior

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        djdevs
                        wrote on last edited by
                        #11

                        I'm not able to see the video link, probably because the post is quite long ago.
                        The issue that I see from the code above is the data is not able to be transferred from the drag area to the drop area between different windows.

                        To resolve the issue, I had save the value in the property of the drag area, and retrieved this value from the drop area.
                        Here's the full code. Code changes are commented as //Changes here

                        import QtQuick 2.2
                        import QtQuick.Window 2.0
                        
                        Window {
                            width: 800
                            height: 600
                            visible: true
                        
                            ListView {
                                id: list
                                anchors.fill: parent
                        
                                model: 5
                        
                                delegate: Rectangle {
                                    width: list.width
                                    height: 30
                                    border.color: "black"
                                    border.width: 1
                        
                                    Text {
                                        anchors.fill: parent
                                        text: index
                                    }
                        
                                    Item {
                                        id: draggable
                                        anchors.fill: parent
                                        property var saved_value //Changes here
                        
                                        Drag.active: mouseArea.drag.active
                                        Drag.hotSpot.x: 0
                                        Drag.hotSpot.y: 0
                                        Drag.mimeData: {
                                            "mediaItem": index
                                        }
                                        Drag.dragType: Drag.Automatic
                                        Drag.onDragStarted: {
                                            saved_value = index //Changes here
                                        }
                                        Drag.onDragFinished: {
                        
                                        }
                                    }
                        
                                    MouseArea {
                                        id: mouseArea
                                        anchors.fill: parent
                        
                                        drag.target: draggable
                                    }
                                }
                            }
                        
                            Window {
                                visible: true
                        
                                Text {
                                    id: text
                                    anchors.fill: parent
                                }
                        
                                DropArea {
                                    anchors.fill: parent
                        
                                    keys: ["mediaItem"]
                        
                                    onDropped: drop => {
                                                   text.text += drop.source.saved_value //Changes here
                                                   drop.acceptProposedAction()
                                               }
                                }
                            }
                        }
                        
                        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