C++ QCustomPlot QCPItemEllipse位置
我有一个中心为(0,0)的QCustomPlot图,我想在图上的所有数据周围添加一个椭圆项,但在那里我只能设置椭圆的左上角和右下角位置,这几乎显示在图表的中心,但有点偏离,因为我无法设置椭圆的中心,因为中心不是一个位置,而是一个锚 有人知道如何将椭圆项目的中心设置为(0,0)吗C++ QCustomPlot QCPItemEllipse位置,c++,qt,qcustomplot,C++,Qt,Qcustomplot,我有一个中心为(0,0)的QCustomPlot图,我想在图上的所有数据周围添加一个椭圆项,但在那里我只能设置椭圆的左上角和右下角位置,这几乎显示在图表的中心,但有点偏离,因为我无法设置椭圆的中心,因为中心不是一个位置,而是一个锚 有人知道如何将椭圆项目的中心设置为(0,0)吗 伙计,椭圆中心的位置是由它的左上和右下两个点决定的 例如,center.x==(topLeft.x+bottomRight.x)/2和center.y==(topLeft.y+bottomRight.y)/2。这就是椭圆
伙计,椭圆中心的位置是由它的左上和右下两个点决定的 例如,
center.x==(topLeft.x+bottomRight.x)/2
和center.y==(topLeft.y+bottomRight.y)/2
。这就是椭圆在数学中的作用:)
在您的代码中,如果(lowestX+hightX)==0
,(lowestY+hightY)==0,则中心将位于(0,0)
或者我不明白你在说什么
如果您想以简单的方式移动椭圆的中心,可以使用字段QCPItemTracer*mCenterTracer
和构造函数中的以下内容创建从QCPITEMLLIPSE
派生的类:
mCenterTracer->setStyle(QCPItemTracer::tsNone);
topLeft->setParentAnchor(mCenterTracer->position);
bottomRight->setParentAnchor(mCenterTracer->position);
topLeft->setCoords(-xRadius/2.0, -yRadius/2.0);
bottomRight->setCoords(xRadius/2.0, yRadius/2.0);
所以移动中心(不改变半径)的方法如下所示:
void FreakingEllipse::moveCenter(double x, double y) {
mCenterTracer->position->setCoords(x, y);
}
顺便说一下,如果希望椭圆的半径(以像素为单位)保持不变,而椭圆的中心仍然是绘图坐标,则可以添加以下内容:
void FreakingEllipse::moveCenter(double x, double y) {
mCenterTracer->position->setCoords(x, y);
}
topLeft->setType(QCPItemPosition::ptAbsolute);
bottomRight->setType(QCPItemPosition::ptAbsolute);