Qt(QML)虚线圆 [英] Qt (QML) Dashed Circle
本文介绍了Qt(QML)虚线圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在QML中绘制半虚线圆吗?我以这种方式画了半圈
Is there any way to draw half dashed circle in QML? I drawn half circle in this way
var Circle = getContext("2d");
Circle.save();
var CircleGradient =
Circle.createLinearGradient(parent.width/4,parent.height,parent.width/4,0);
CircleGradient.addColorStop(0, firstGradientPoint);
CircleGradient.addColorStop(1, secondGradientPoint);
Circle.clearRect(0, 0, parent.width, parent.height);
Circle.beginPath();
Circle.lineCap = "round";
Circle.lineWidth = 10;
Circle.strokeStyle = CircleGradient
Circle.arc(parent.width/2, parent.height/2, canvas.radius - (Circle.lineWidth / 2), Math.PI/2, canvas.Value);
Circle.stroke();
Circle.restore();
结果
但是我怎么能像这样破折号呢?
But how can I make it dashed like this.
我需要
推荐答案
我知道这个问题已经过时了,但它可能会对某人有所帮助.您可以使用 Qt快速形状(自Qt 5.10)呈现您想要的内容.它不是复制粘贴代码,而是更多方法:
I know that this question is very outdated, but it might help someone. You can use Qt Quick Shapes (since Qt 5.10) to render what you want. It's not copy-paste code, but more of an approach:
Shape {
ShapePath {
id: shapePath
strokeColor: "black"
strokeStyle: ShapePath.DashLine
dashPattern: [6, 8]
fillColor: "transparent"
PathArc {
x: 0
y: radiusX + radiusY
radiusX: 100
radiusY: 100
useLargeArc: true
}
}
}
PathArc 文档包含了您所需的几乎所有内容.这里还有一些形状示例.
PathArc documentation has pretty much everything you need. Here are some more Shape Examples.
这篇关于Qt(QML)虚线圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文