QtQuick pathCurve 鼠标点击事件上的曲线
QtQuick pathCurve curve line on mouse click event
嘿发布这个问题来学习如何在点击时弯曲一条线,即使用路径曲线我想弯曲一条线但不是硬编码它发生在鼠标点击事件上就像点击 (400,320) 然后在那条线位置 Y 位置将改变(比如 +75),因为它是硬编码的图像,但我想要曲线 onclick 无论鼠标点击事件发生在哪里它应该曲线
这是我的实现。这不是你想要的形状。似乎您无法通过 PathCurve
获得类似您的图像的东西,但您肯定可以通过 PathCubic[= 更好地控制结果18=].
Canvas {
id: canvas
width: 640; height: 640
contextType: "2d"
Path {
id: myPath
startX: 320; startY: 0
PathCurve { id: curvePoint_top; x: 320; y: curvePoint.y - 80 }
PathCurve { id: curvePoint; x: 320; y: 320 }
PathCurve { id: curvePoint_bottom; x: 320; y: curvePoint.y + 80 }
PathCurve { x: 320; y: 640 }
}
onPaint: {
context.clearRect(0,0,width,height);
context.strokeStyle = Qt.rgba(.4,.6,.8);
context.path = myPath;
context.stroke();
}
MouseArea{
anchors.fill: parent
onClicked: {
curvePoint.x = mouseX;
curvePoint.y = mouseY;
canvas.requestPaint();
}
}
}
嘿发布这个问题来学习如何在点击时弯曲一条线,即使用路径曲线我想弯曲一条线但不是硬编码它发生在鼠标点击事件上就像点击 (400,320) 然后在那条线位置 Y 位置将改变(比如 +75),因为它是硬编码的图像,但我想要曲线 onclick 无论鼠标点击事件发生在哪里它应该曲线
这是我的实现。这不是你想要的形状。似乎您无法通过 PathCurve
获得类似您的图像的东西,但您肯定可以通过 PathCubic[= 更好地控制结果18=].
Canvas {
id: canvas
width: 640; height: 640
contextType: "2d"
Path {
id: myPath
startX: 320; startY: 0
PathCurve { id: curvePoint_top; x: 320; y: curvePoint.y - 80 }
PathCurve { id: curvePoint; x: 320; y: 320 }
PathCurve { id: curvePoint_bottom; x: 320; y: curvePoint.y + 80 }
PathCurve { x: 320; y: 640 }
}
onPaint: {
context.clearRect(0,0,width,height);
context.strokeStyle = Qt.rgba(.4,.6,.8);
context.path = myPath;
context.stroke();
}
MouseArea{
anchors.fill: parent
onClicked: {
curvePoint.x = mouseX;
curvePoint.y = mouseY;
canvas.requestPaint();
}
}
}