Drag Distance



  • Hello,

    so I am currently working on a nice little app and need some help. In the app there is a grid where the user can create widgets at any position. If a user created a widget I want him to be able to drag the widget to another position in the grid.

    Actually its all working perfectly fine with the following code, except a little thing that is bothering me.

    MouseArea {
    id: dragTool
    anchors.fill: parent
    drag.target: tool
    drag.minimumX: 2
    drag.maximumX: grid.width
    drag.minimumY: 2
    drag.maximumY: grid.height
    }

    With that code the widget can be moved in a way that it does not align with the grid anymore. To fix that, the user should be only able to move the widget for a certain amount of pixels (e.g. when the widget is moved to the left, it does instantly move 100px to the left, if it gets dragged even further 200px .. 300px ....)

    Is there any possibility to do this?


  • Moderators

    Hi @DanBoSlice,
    One way I think would be to check the threshold for eg. here a value for x property in onXChanged handler.

    onXChanged: if( x < -2) x = -100
    

Log in to reply
 

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