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

Drag and Drop of underlying Mousearea



  • HI,
    I want to be able when doing a PressAndHold on a TextEdit to be able to drag its parent mousearea. To enter new text I would do a double click to focus on TextEdit.
    I thought I could do it using propagateComposedEvents.
    Using it I can detect a click of the top mousearea in the parent mousearea but I can not drag the parent mousearea itself.
    Here is a very simplified code of what I tryed:

    Window {
        visible: true
        width: 640
        height: 480
    
        Rectangle {
            id: parentRectangle
            height: 200
            width: 400
            color: "red"
    
            Drag.active: parentRectangleMousearea.drag.active
            Drag.hotSpot.x: 10
            Drag.hotSpot.y: 10
    
            MouseArea {
                id: parentRectangleMousearea
                anchors.fill: parent
                onClicked: console.log("Red parent rectangle clicked.")
                drag.target: parentRectangle
            }
    
            Rectangle {
                id: childRectangle
    
                height: 100
                width: 200
                color: "blue"
    
                MouseArea {
                    id: childRectangleMousearea
    
                    anchors.fill: parent
                    propagateComposedEvents: true
                    onClicked: {
                        console.log("Blue child rectangle clicked.")
                        mouse.accepted = false
                    }
                }
            }
        }
    }
    

    Clicking on the red rectangle shows "Red parent rectangle clicked" in the console.
    Clicking on the red rectangle shows "Red parent rectangle clicked" and "Blue parent rectangle clicked" in the console. So the propagation seems to work.
    I can also drag the red rectangle when I press and hold the red rectangle.
    But I can not drag the red rectangle when I press and hold the blue rectangle.

    Do someone has an idea how I could achieve by and press and hold on a textedit to drag its underlying element and focus on the textedit if I double click.

    Thanks a lot in advance,

    Emmanuel


Log in to reply