如何获得QPieSlice (中心)的坐标?
背景:我想将一个“标注”请看这里添加到我的QChart中,它显示一个QPieSeries。我已经把悬停信号连接到一个定制的插槽。在这个插槽中,我可以访问QPieSlice。要显示我的“标注”,我需要QChart坐标系中的x和y坐标。“标注”的锚应该是我目前悬停的QPieSlice的中心。
怎样才能得到QPieSlice中心的坐标?
我试过这样的方法:
double angle = pieSlice->startAngle()+pieSlice->angleSpan()/2;
double x = 1*cos(angle*deg2rad);
double y = 1*sin(angle*deg2rad);
callout->setAnchor(QPointF(x,y));发布于 2018-08-06 08:55:32
你也要把半径带进去。
如果你想得到中心,你把你的曲线半径的一半作为公式的输入,在下面给出的圆上得到点:
x = cx + r * cos(a)
y = cy + r * sin(a)因此,结合您的代码,这将提供:
double angle = pieSlice->startAngle()+pieSlice->angleSpan()/2;
double calloutRadius= plotRadius*0.5;
double x = centerPlotX + calloutRadius*cos(angle*deg2rad);
double y = centerPlotY + calloutRadius*sin(angle*deg2rad);
callout->setAnchor(QPointF(x,y));哪里
plotRadius = Radius of your pie plot
centerPlotX = the X center of your pie plot
centerPlotY = the Y center of your pie plothttps://stackoverflow.com/questions/51703436
复制相似问题