简体   繁体   English

Qt (QML) 虚线圆圈

[英]Qt (QML) Dashed Circle

Is there any way to draw half dashed circle in QML?有没有办法在 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();

Result结果

But how can I make it dashed like this.但我怎样才能让它像这样破灭。

I need我需要

I know QML little bit but never coded.我对 QML 有一点了解,但从未编码过。 But you can solve your problem by logic.但是你可以通过逻辑来解决你的问题。

Here is the logic- Code below is pseudo, will not work but will give you an idea.这是逻辑 - 下面的代码是伪代码,不起作用,但会给你一个想法。

Draw the small arcs in loop with spaces in between.在循环中绘制小圆弧,中间有空格。

//DECLARE YOUR ANGLES START AND END
startAngle = 0.0;
endAngle = pi/20;// 10 ARCS AND 10 SPACES

 while (q++ < 10){

   Circle.arc(parent.width/2, parent.height/2, canvas.radius - (Circle.lineWidth / 2), startAngle, endAngle, canvas.Value)

   //LEAVE SPACE AND CREATE NEW START AND END ANGLE.
   startAngle = endAngle + endAngle;
   endAngle  = startAngle + endAngle;
 }

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.您可以使用Qt Quick Shapes (自 Qt 5.10 起)来渲染您想要的内容。 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 documentation has pretty much everything you need. PathArc文档几乎包含您需要的一切。 Here are some more Shape Examples .这里有一些更多的形状示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM