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

Qt 5.10 Drag and drop



  • Hi,

    I have a problem with my drag and drop system since I built my project with Qt 5.10.

    My dragged object is still in a dragging state even after the event "dragFinished" is called. So if I do another drag move anywhere in my window it will redo the drag and drop of my object mentioned before.

    I wonder if I have to use the new DragHandler qml object. If it's a bug coming from Qt 5.10. Or if I did it wrong and it worked fine by some way with Qt 5.9.3.

    Thanks.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you can create a minimal compilable example that shows the difference of behaviour between the two Qt versions then you may have found something.

    You can also check the bug report system.



  • Thank you for answering and welcoming me :)

    I found this bug that could be related to mine.

    Here is a minimal code that reproduce my problem:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            id: container
            anchors.fill: parent
            color: "#fefefe"
            width: 640
            height: 480
            DropArea{
                id: dropArea
                anchors.fill: parent
                onDropped: console.log("drop handler")
            }
    
            MouseArea {
                id: mouseArea
                drag.target: dragButton
                drag.axis: Drag.XAndYAxis
                anchors.right: parent.right
                anchors.top: parent.top
                width: 80
                height: 80
                Rectangle {
                    id: dragButton
                    color: "#ff0000"
                    anchors.fill: parent
                    Drag.active: mouseArea.drag.active
                    Drag.dragType: Drag.Automatic
                }
            }
            states: [
                State {
                    name: "dragState"
                    when: dropArea.containsDrag
                    PropertyChanges {
                        target: container
                        color: "#777777"
                    }
                }
            ]
        }
    }
    


  • This post is deleted!


  • @Entrevrak Hello, I think if you use Connexion insted of binding (onDropped ) it will work again.



  • @LeLev Hello,

    If you meant:

    Connections {
                target: dropArea
                onDropped: {
                    console.log("drop handler")
                }
            }
    

    No it does not work.



  • @Entrevrak then sorry :/ i don't have auther idea


  • Lifetime Qt Champion

    Can you describe what should happen ?

    On my system with both 5.10 and 5.8 (using qmlscene to run your sample) I have a red square that doesn't move but the onDropped slot gets called.



  • Sorry I hope my next explanation will be better.

    The only thing my sample code should do is on drag and drop from the red square to the dropArea.

    But in Qt 5.10, I can keep doing drag and drop event from anywhere in the window.

    Here is a gif showing the problem:

    0_1513239774855_dragDropBug.gif


  • Lifetime Qt Champion

    Ok, so just to be sure:

    • Drag the red square once
    • Drop
    • Drag can now be done from anywhere else

    Is that correct ?



  • Yes, correct.


  • Lifetime Qt Champion

    Then I don’t have that behavior on macOS with my 5.10 build.

    I’ll check with the official release.



  • You're right I tested out on macOS and the problem wasn't there.
    I tried on Windows 7 and Windows 10 and both have the problem.

    Thanks for the info, I did not thought of testing on another OS.


Log in to reply