Advertisement
artemmarchenko

Moving inner rectangle while mouse is pressed

Aug 19th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 1.0
  2.  
  3. Rectangle {
  4.     width: 640
  5.     height: 480
  6.     color: "lightyellow"
  7.  
  8.     Rectangle {
  9.         x: 20
  10.         y: 20
  11.         width: 60
  12.         height: 48
  13.         color: "red"
  14.         MouseArea {
  15.             anchors.fill: parent
  16.             property int startingMouseX: 0
  17.             property int startingMouseY: 0
  18.             onPressed: {
  19.                 startingMouseX = mouse.x
  20.                 startingMouseY = mouse.y
  21.             }
  22.  
  23.             onMousePositionChanged: {
  24. //                console.log("MousePositionChanged to " + mouse.x + ", " +mouse.y)
  25.                 parent.x += mouse.x - startingMouseX
  26.                 parent.y += mouse.y - startingMouseY
  27.             }
  28.  
  29.         }
  30.     }
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement