Qt (QML) Dashed Circle

萝らか妹 提交于 2019-12-13 17:44:17

问题


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();

Result

But how can I make it dashed like this.

I need


回答1:


I know QML little bit but never coded. 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;
 }


来源:https://stackoverflow.com/questions/45309676/qt-qml-dashed-circle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!