繁体   English   中英

QCustomPlot QCPItemEllipse位置

[英]QCustomPlot QCPItemEllipse position

我有一个QCustomPlot Graph,其中心为(0,0),我想在图形上的所有数据周围添加一个椭圆项,但是我只能设置椭圆的左上角和右下角位置,这几乎显示为图形的中心,但是有点偏离,因为我无法将椭圆设置为中心,因为中心不在其锚点的位置

有谁知道我如何将椭圆项的中心设置为(0,0)?

    QCPItemEllipse *ellipse = new QCPItemEllipse(ui->customPlot);
    ellipse->setAntialiased(true);
    ellipse->topLeft->setCoords(lowestX, highestY);
    ellipse->bottomRight->setCoords(highestX, lowestY);

男人,椭圆中心的位置取决于它的左上角和右下角。

例如center.x == (topLeft.x + bottomRight.x)/2center.y == (topLeft.y + bottomRight.y)/2 这就是椭圆在数学中的工作方式:)。

在您的代码中,如果(lowestX + hightX) == 0(lowestY + hightY) == 0 ,则中心将位于(0,0)中。

也许我不明白你在说什么?

如果要以简单的方式移动椭圆的中心,则可以使用字段QCPItemTracer *mCenterTracer和构造函数中的以下内容创建从QCPItemEllipse派生的类:

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM