Qt Coordinates of QPieSlice
Qt Coordinates of QPieSlice
如何获取QPieSlice(中心(的坐标?
背景:我想在显示QPieSeries的QChart中添加一个"标注"。我已将悬停信号连接到自定义插槽。在这个插槽中,我可以访问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));
您还需要将半径计算在内。
如果你想得到中心,你可以把绘图半径的一半作为公式的输入,得到下面给出的圆上的点:
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
相关文章:
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 赛通"Cannot take address of memoryview slice"
- C++ Version Of Double.longBitsToDouble
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ Usage of AsyncCallback
- 错误:"Left of getValue must have class/struct/union"
- Centos7 g++ "to_string is not in a member of std"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 传递 std::vector of std::shared_ptr,而不是更新对象
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- Qt Coordinates of QPieSlice