QPieSlice的Qt坐标

Qt Coordinates of QPieSlice

如何获取 QPieSlice(中心)的坐标?

背景: 我想向显示 QPieSeries 的 QChart 添加 "Callout" see here。 我已将悬停信号连接到自定义插槽。在这个插槽中,我可以访问 QPieSlice。 要显示我的 "Callout" 我需要 QChart 坐标系中的 x 和 y 坐标。 "Callout" 的锚点应该是我当前悬停的 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));

你还需要考虑半径。

如果您想获得圆心,您可以将绘图半径的一半作为公式的输入,以获得下面给出的圆上的点:

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 plot