Advertisement
Guest User

Ondra-QML

a guest
Apr 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 0.98 KB | None | 0 0
  1. import QtQuick 2.7
  2. //import Qt.WebSockets 1.0
  3.  
  4. Item {
  5.     id: root
  6.  
  7.     width: 1200
  8.     height: 816
  9.  
  10.     Canvas {
  11.         id: canvas
  12.  
  13.         anchors.fill: parent
  14.  
  15.         onPaint: {
  16.             console.log(mouseArea.mousePos)
  17.             var ctx = canvas.getContext('2d')
  18.             ctx.clearRect(0, 0, canvas.width, canvas.height)
  19.             ctx.beginPath()
  20.             ctx.strokeStyle = "#FF000"
  21.             ctx.lineWidth = 1
  22.             ctx.moveTo(0, 0)
  23.             ctx.lineTo(mouseArea.mousePos.x, mouseArea.mousePos.y)
  24.             ctx.closePath()
  25.             ctx.stroke()
  26.         }
  27.     }
  28.  
  29.  
  30.     MouseArea {
  31.         id: mouseArea
  32.  
  33.         property var mousePos: Qt.point(0, 0)
  34.  
  35.         hoverEnabled: true
  36.         anchors.fill: parent
  37.  
  38.         onMouseXChanged: {
  39.             mousePos.x = mouse.x
  40.             canvas.requestPaint()
  41.         }
  42.  
  43.         onMouseYChanged: {
  44.             mousePos.y = mouse.y
  45.             canvas.requestPaint()
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement