OnEntered during mouse drag



  • Hello,

    Please teach me how to make an onEntered event happen while I'm dragging movableObject.

    I wrote the following code:
    @import QtQuick 2.0

    Rectangle {
    id: window
    width: 200
    height: 200

    Rectangle {
        id: movableObject
        width: 50; height: 50
        border.color: "black"
    
        MouseArea {
            anchors.fill: parent
            drag.target: parent
        }
    }
    
    Rectangle {
        id: hoverArea
        x: 100; y: 100;
        width: 50; height: 50
        border.color: "blue"
    
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onEntered: {
                console.log("entered"); // this event doesn't happen while I'm dragging movableObject.
            }
        }
    }
    

    }
    @



  • Shouldn't the drag.target on line 15 be movableObject? Do not know if it helps?

    EDIT: No parent should be fine



  • Thanks for your reply, Hykkel.

    If I delete the line 15, movableObject will not be able to drag.
    I think I have to set movableObject to drag.target.



  • Hi.

    I was looking for something else, when I stumbled across this. Maybe you can make a workaround using states and containsMouse (see e.g. last codeexample).

    http://qt-project.org/doc/qt-4.8/qml-behaviors-and-states.html

    It may not be the best solution, but maybe you can get it working.



  • Thanks Hykkel

    I checked the article and wrote code below.
    I added states attribute but myEntered() is not called during dragging movableObject.
    (When a mouse enters hoverAreaMouser without dragging, myEntered() is called.)
    @import QtQuick 2.0

    Rectangle {
    id: window
    width: 200
    height: 200

    Rectangle {
        id: movableObject
        width: 50; height: 50
        border.color: "black"
    
        MouseArea {
            anchors.fill: parent
            drag.target: parent
        }
    }
    
    Rectangle {
        x: 100; y: 100;
        width: 50; height: 50
        border.color: "blue"
    
        MouseArea {
            id: hoverAreaMouser
            anchors.fill: parent
            hoverEnabled: true
            function myEntered() {
                console.log("entered");
            }
        }
    
        states: State {
            when: hoverAreaMouser.containsMouse
            StateChangeScript {
                script: hoverAreaMouser.myEntered();
            }
        }
    }
    

    }@



  • Weird!

    Hoped the workaround might have worked.

    The mouse event seems to be suppressed (like when using propagateComposedEvents: or preventStealing:). Perhaps this is the issue? I'm afraid we need some expert on this... it's probably some simple setting. A bug like this would have been caught - right?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.