QcustomPlot坐标鼠标跟随--Apple的学习笔记
2019-11-23 本文已影响0人
applecai
网上参考了别人的设计。自己练手也做了个带鼠标吸附功能进行坐标显示的plot曲线,可缩放及平移。基于QT5.12和QcutomPlot2.0.1
吸附坐标点的关键代码
void myTracer::traceGraph(double xValue,double &xx,double &yy)
{
tracer->setGraph(plot->graph(0));//设置游标吸附在traceGraph这条曲线上
tracer->setGraphKey(xValue);//设置游标的X值(这就是游标随动的关键代码)
xx = tracer->position->key();
yy = tracer->position->value();
m_lineV->point1->setCoords(xx, 1);
m_lineV->point2->setCoords(xx, 0);
m_lineH->point1->setCoords(-1,yy);
m_lineH->point2->setCoords(1,yy);
}
效果如下:

