简体   繁体   中英

How to draw an arc between two known points in Qt?

在此处输入图像描述

I want to draw an arc between point B to point D and it should touch to point E. ( I want to draw AND gate symbol )
I tried this way

QPainterPath path;    
path.arcTo(60,30,46,100,30*16,120*16); // ( x,y,width,height, startAngle,spanAngle)       

But it is drawing full circle and not in proper place.

Currently it is looking like this

在此处输入图像描述

After getting suggestion I tried like this :

path.moveTo(106, 80);
path.arcTo(76.0, 30.0, 60.0, 100.0, 90.0, -180.0);    

How to get rid of that vertical line ( inside AND gate ) ?
Why it is appearing ?

I think you misunderstood the parameters for arcTo , especially the bounding rectangle.

Given your image, you should move path to (106, 80) (center of the bounding rectangle)

path.moveTo(106, 80) ;

The bounding rectangle of the arc should look like this:

  • x: 76
  • y: 30
  • width: 60
  • height: 100

The arc itsel should have a start angle at 90° and should span 180° in negative direction.

This results in:

path.arcTo(76.0, 30.0, 60.0, 100.0, 90.0, -180.0);

Update

arcTo

path.moveTo(106, 30);
path.cubicTo(QPointF(156.0, 30.0), QPointF(156.0, 130.0), QPointF(106.0, 130.0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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