我有一个中心为(0,0)的QCustomPlot图,我想在图上的所有数据周围添加一个椭圆项,但是在那里我只能设置椭圆的左上角和右下角的位置,这几乎显示在图的中心,但是它有点偏离,因为im不能将中心设置为椭圆中心,而不是定位它的锚。
有人知道我如何能够将椭圆项的中心设置为(0,0)吗?
QCPItemEllipse *ellipse = new QCPItemEllipse(ui->customPlot);
ellipse->setAntialiased(true);
ellipse->topLeft->setCoords(lowestX, highestY);
ellipse->bottomRight->setCoords(highestX, lowestY);发布于 2013-11-01 16:12:55
人,椭圆的中心位置是由它的左上角和右下角决定的。
例如center.x == (topLeft.x + bottomRight.x)/2和center.y == (topLeft.y + bottomRight.y)/2。这就是椭圆在数学中的工作原理:)。
在您的代码中,如果是(lowestX + hightX) == 0 & (lowestY + hightY) == 0,中心将位于(0,0)中。
或者我不明白你在说什么?
如果您想以简单的方式移动椭圆的中心,可以使用字段QCPItemEllipse和构造函数中的以下内容创建从QCPItemTracer *mCenterTracer派生的类:
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);
}顺便说一句,如果您希望椭圆的半径不变(以像素为单位),而它的中心仍然坚持绘图坐标,您可以添加以下内容:
topLeft->setType(QCPItemPosition::ptAbsolute);
bottomRight->setType(QCPItemPosition::ptAbsolute);https://stackoverflow.com/questions/19632468
复制相似问题