Mouse Event Drag Release



  • Hi

    I am using MouseArea of a MapQuickItem for dragging the item.

     MouseArea{
    
            anchors.fill:  parent
            id: _markerMouseArea
            drag.target: parent
            drag.minimumX:  0;
            drag.minimumY:  0;
            preventStealing: true
            hoverEnabled: true
            cursorShape: Qt.OpenHandCursor
         
    
            acceptedButtons:  Qt.LeftButton
    
    
    
            onReleased: {
                console.log("Released")
                updateCoordinate()
            }
    
    
    
        }
    

    Many times the mouse release event is not being recognized and hence misses to call the function updateCoordinate() but the object is in the new position. What could be the issue?

    Also, the cursor shape does not change when the object is interacted.

    Thanks!



  • Hi Saitej,

    I got a similiar issue when I tried to do some thing on onReleased event of MouseArea. In my case I pressed mouse area and started doing my stuff.
    But in between I lost the focus from mouse area (By some other action eg:- Alt + tab key pressed) and missed to get the onReleased event.
    From that I understood that OnReleased called only if I pressed/dragged and released the mouse normally without any interference like focus change by other means. So I changed my code by using onPressedChanged instead of onReleased.

    onReleased: { /// No guarantee to get invoked always when i released the mouse(unless it has focus)
    }

    onPressedChanged: {
    if(pressed) {
    /// Mouse is in pressed state.
    }
    else {
    /// Mouse released. Either by user released the mouse button or by focus change to any other control.
    /// Here it is ensured that release will executed.
    }
    }



  • Thanks a lot man!!

    It seems to work better than before but I need to give it more tests.



  • @saitej You are welcome.


Log in to reply
 

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