Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Drag cross window



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



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





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



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



  • @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



  • @Danima - I cannot make your code run.



  • @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?



  • @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



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



  • @Danima
    no other idea?


  • Qt Champions 2018

    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



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



  • @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



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


Log in to reply