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 cross window
Qt 6.11 is out! See what's new in the release blog

Drag cross window

Scheduled Pinned Locked Moved Solved QML and Qt Quick
15 Posts 3 Posters 2.8k 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.
  • MarkkyboyM Markkyboy

    Possible duplicate: https://forum.qt.io/topic/45462/drag-and-drop-in-separate-windows ( read all comments for clarity)

    check out the above link, it may give you a clue :)

    DanimaD Offline
    DanimaD Offline
    Danima
    wrote on last edited by
    #4

    @Markkyboy
    I checked link and add line below to solve problem. Now dragging works between two windows but the target does not move when dragging. how can solve this problem? You might say that the target cannot be displayed outside the parent window but
    It doesn't matter. I just want to see movement of the target inside the parent window.

    MarkkyboyM 1 Reply Last reply
    0
    • DanimaD Danima

      @Markkyboy
      I checked link and add line below to solve problem. Now dragging works between two windows but the target does not move when dragging. how can solve this problem? You might say that the target cannot be displayed outside the parent window but
      It doesn't matter. I just want to see movement of the target inside the parent window.

      MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #5

      @Danima - without seeing your code, I can't say. I am also still a bit of a noob with QML.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      DanimaD 1 Reply Last reply
      0
      • MarkkyboyM Markkyboy

        @Danima - without seeing your code, I can't say. I am also still a bit of a noob with QML.

        DanimaD Offline
        DanimaD Offline
        Danima
        wrote on last edited by Danima
        #6

        @Markkyboy
        main.qml:

        import QtQuick 2.12
        import QtQuick.Window 2.12
        import QtQuick.Controls 2.12
        
        Window {
            id:window1
            visible: true
            width: 300
            height: 200
            x:400
            y:400
            title: qsTr("Hello World")
        
        
            Rectangle
            {
                anchors.fill: parent
                color:dropArea.containsDrag? "green" : "gray"
                DropArea
                {
                    id:dropArea
                    anchors.fill: parent
                }
        
                Text{
                    anchors.fill: parent
                    text:"Window1"
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                }
        
            }
        
            Window
            {
                id:window2
                visible: true
                width: 200
                height: 100
                y:400
                x:100
        
                flags: Qt.FramelessWindowHint
        
        
                Page
                {
                    anchors.fill: parent
        
                    header:WindowDrager
                    {
                        height:24
                        window:window2
                    }
        
                    contentItem: Rectangle{
                        color:"yellow"
                        Text{
                            anchors.fill: parent
                            text:"Window2"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
        
                    }
                }
        
            }
        
        
        }
        

        WindowDrager.qml

        import QtQuick 2.0
        import QtQuick.Window 2.12
        import QtQuick.Controls 2.12
        
        Rectangle
        {
            id:root
            property Window window:null
            color:"green"
        
            Item
            {
                id:dummyItem//drag.target should be an Item, while a window is not an Item
                Drag.dragType: Drag.Automatic
                Drag.active: mouseArea.drag.active
        
                onXChanged:
                {
                    window.x +=x;
                    x=0;
                }
                onYChanged:
                {
                    window.y +=y;
                    y=0;
                }
        
            }
        
        
            MouseArea
            {
                id: mouseArea
                anchors.fill: parent
                drag.target: dummyItem
            }
        
            Button
            {
                height: 16
                width:16
                padding: 0
                anchors.rightMargin: 4
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                onClicked:window.close()
                text:"X"
            }
        }
        

        I add line "Drag.dragType: Drag.Automatic" to drag work between two window but when dragging the window2 does not move. if I remove above line window2 moves and dragging not work.

        qmlWindowDrag.png

        MarkkyboyM 1 Reply Last reply
        0
        • DanimaD Danima

          @Markkyboy
          main.qml:

          import QtQuick 2.12
          import QtQuick.Window 2.12
          import QtQuick.Controls 2.12
          
          Window {
              id:window1
              visible: true
              width: 300
              height: 200
              x:400
              y:400
              title: qsTr("Hello World")
          
          
              Rectangle
              {
                  anchors.fill: parent
                  color:dropArea.containsDrag? "green" : "gray"
                  DropArea
                  {
                      id:dropArea
                      anchors.fill: parent
                  }
          
                  Text{
                      anchors.fill: parent
                      text:"Window1"
                      verticalAlignment: Text.AlignVCenter
                      horizontalAlignment: Text.AlignHCenter
                  }
          
              }
          
              Window
              {
                  id:window2
                  visible: true
                  width: 200
                  height: 100
                  y:400
                  x:100
          
                  flags: Qt.FramelessWindowHint
          
          
                  Page
                  {
                      anchors.fill: parent
          
                      header:WindowDrager
                      {
                          height:24
                          window:window2
                      }
          
                      contentItem: Rectangle{
                          color:"yellow"
                          Text{
                              anchors.fill: parent
                              text:"Window2"
                              verticalAlignment: Text.AlignVCenter
                              horizontalAlignment: Text.AlignHCenter
                          }
          
                      }
                  }
          
              }
          
          
          }
          

          WindowDrager.qml

          import QtQuick 2.0
          import QtQuick.Window 2.12
          import QtQuick.Controls 2.12
          
          Rectangle
          {
              id:root
              property Window window:null
              color:"green"
          
              Item
              {
                  id:dummyItem//drag.target should be an Item, while a window is not an Item
                  Drag.dragType: Drag.Automatic
                  Drag.active: mouseArea.drag.active
          
                  onXChanged:
                  {
                      window.x +=x;
                      x=0;
                  }
                  onYChanged:
                  {
                      window.y +=y;
                      y=0;
                  }
          
              }
          
          
              MouseArea
              {
                  id: mouseArea
                  anchors.fill: parent
                  drag.target: dummyItem
              }
          
              Button
              {
                  height: 16
                  width:16
                  padding: 0
                  anchors.rightMargin: 4
                  anchors.right: parent.right
                  anchors.verticalCenter: parent.verticalCenter
                  onClicked:window.close()
                  text:"X"
              }
          }
          

          I add line "Drag.dragType: Drag.Automatic" to drag work between two window but when dragging the window2 does not move. if I remove above line window2 moves and dragging not work.

          qmlWindowDrag.png

          MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by
          #7

          @Danima - I cannot make your code run.

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          DanimaD 1 Reply Last reply
          0
          • MarkkyboyM Offline
            MarkkyboyM Offline
            Markkyboy
            wrote on last edited by Markkyboy
            #8

            @Danima - Okay, I built the project again and now it works, provided you grab Window2 by the green bar it does drag, so I cannot see what the problem is for now.

            Suggestion: scrap your current build and start again using the code you have pasted here. I don't why this should make any difference, but it is working for me. Window 2 is draggable with the code you have pasted here......weird.

            Ahh, okay, I see what you mean now, the green/yellow window is not actually visibly moving when it is dragged, is this what you are getting at?

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            1 Reply Last reply
            1
            • MarkkyboyM Markkyboy

              @Danima - I cannot make your code run.

              DanimaD Offline
              DanimaD Offline
              Danima
              wrote on last edited by Danima
              #9

              @Markkyboy

              Ahh, okay, I see what you mean now, the green/yellow window is not actually visibly moving when it is dragged, is this what you are getting at?

              Yes that is it

              I uploaded code:
              https://github.com/hoss291069/QmlWindowDrager.git

              1 Reply Last reply
              0
              • MarkkyboyM Offline
                MarkkyboyM Offline
                Markkyboy
                wrote on last edited by
                #10

                @Danima - I've been playing extensively with your code but cannot get your desired result.

                Have a look at 'drag and drop' examples within QtCreator, perhaps it might give a clue, particularly look at the example with red and blue tiles.

                Don't just sit there standing around, pick up a shovel and sweep up!

                I live by the sea, not in it.

                1 Reply Last reply
                0
                • DanimaD Danima

                  How can drag and drop to DopeArea in other window of same application?

                  DanimaD Offline
                  DanimaD Offline
                  Danima
                  wrote on last edited by
                  #11

                  @Danima
                  no other idea?

                  1 Reply Last reply
                  0
                  • GrecKoG Offline
                    GrecKoG Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on last edited by
                    #12

                    My guess is that you would have to handle the dragging yourself.

                    I did a little PoC some times ago : https://gist.github.com/oKcerG/79a69de5826917123582480e85e3c317

                    The concept is that the draggable item creates its own temporary window when it is being "dragged".

                    Some work has to be done to be able to use it in production, the main point is to get a better logic for the targetWindow property, for now it justs toggle between both hardcoded window, a good solution would be to get the list of top level windows and check which one applies when the item is dropped.

                    Feel free to ask question about this code

                    DanimaD 2 Replies Last reply
                    0
                    • GrecKoG GrecKo

                      My guess is that you would have to handle the dragging yourself.

                      I did a little PoC some times ago : https://gist.github.com/oKcerG/79a69de5826917123582480e85e3c317

                      The concept is that the draggable item creates its own temporary window when it is being "dragged".

                      Some work has to be done to be able to use it in production, the main point is to get a better logic for the targetWindow property, for now it justs toggle between both hardcoded window, a good solution would be to get the list of top level windows and check which one applies when the item is dropped.

                      Feel free to ask question about this code

                      DanimaD Offline
                      DanimaD Offline
                      Danima
                      wrote on last edited by
                      #13

                      @GrecKo said in Drag cross window:

                      targetWindow

                      Thank you for your suggestion.
                      I had implemented custom drag and drop mechanism but have a bad Weakness.
                      When two drop area overlaps and you drag an item over drop area that was beneath other one target drop doesn't changed in intersect zone to upper dropArea.

                      I unfortunately deleted that code:(

                      I'm trying to rewrite it and post Here.

                      1 Reply Last reply
                      0
                      • GrecKoG GrecKo

                        My guess is that you would have to handle the dragging yourself.

                        I did a little PoC some times ago : https://gist.github.com/oKcerG/79a69de5826917123582480e85e3c317

                        The concept is that the draggable item creates its own temporary window when it is being "dragged".

                        Some work has to be done to be able to use it in production, the main point is to get a better logic for the targetWindow property, for now it justs toggle between both hardcoded window, a good solution would be to get the list of top level windows and check which one applies when the item is dropped.

                        Feel free to ask question about this code

                        DanimaD Offline
                        DanimaD Offline
                        Danima
                        wrote on last edited by
                        #14

                        @GrecKo
                        I wrote that code again and it works. Now the problem is when drag area that overlaps between two or more windows; in this case drop's result is not specified.
                        I uploaded code in GitHub.
                        https://github.com/hoss291069/Qml-Drag-Drop-Between-window.git

                        DanimaD 1 Reply Last reply
                        0
                        • DanimaD Danima

                          @GrecKo
                          I wrote that code again and it works. Now the problem is when drag area that overlaps between two or more windows; in this case drop's result is not specified.
                          I uploaded code in GitHub.
                          https://github.com/hoss291069/Qml-Drag-Drop-Between-window.git

                          DanimaD Offline
                          DanimaD Offline
                          Danima
                          wrote on last edited by
                          #15

                          @Danima
                          I solved that problem for windows platform.
                          https://github.com/hoss291069/Qml-Drag-Drop-Between-window.git

                          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