[英]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)/2
和center.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.