2

I want to draw a special segmented circle like the below image.

But I cannot understand how to draw an arc or ellipse using the setDashPattern.

Image:
enter image description here

At first, I thought that just drawing a colored circle and drawing a transparent rect or line to covered it would work. But it just passed though...

Second, I tried the below code,

QPicture pi;
QPainter p(&pi);
QPen pen(Qt::red);

qreal space = 6;
qreal ine = 99;
pen.setDashPattern(QVector<qreal>() <<
line << space << line << space <<line << space);

p.drawRect(0,50, 100, 100);
p.end();

But this is not what I want it to do.

Does anyone know how to draw rings like this?

Anthropic
  • 681
  • 1
  • 11
  • 29

1 Answers1

0

I suggest to to set a clip path to the painter and draw two complete circles.

You can create a QPainterPath that covers the areas where the circles need to be drawn (black areas). Than set this path to the painter using QPainter::setClipPath(). Finally draw the two circles.

See:

Fabio
  • 2,522
  • 1
  • 15
  • 25
  • Thank you for good keyworkd(ClipPath)..But I think that I have to make a path that black line's path... isn't it ? I think that it needs arc's path.. If I can make this black arcpath, then it is more easy to drawing.. – Dev. HenryHoy Oct 27 '17 at 08:54
  • Yes you are right, I will correct. You can create a path that cover the black areas, adding for examples some polygons, like some "cake slices". – Fabio Oct 27 '17 at 12:19
  • Or you can add a big rectangle to the path that covers all area, and than some polygons as "holes" that cover the "white" areas. Be sure to use Qt::OddEvenFill as fill rule of the path – Fabio Oct 27 '17 at 12:28