Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Drag Distance
Qt 6.11 is out! See what's new in the release blog

Drag Distance

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 995 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DanBoSlice
    wrote on last edited by
    #1

    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?

    p3c0P 1 Reply Last reply
    0
    • D DanBoSlice

      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?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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
      

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved