資源簡(jiǎn)介
這里解決一個(gè)使用圖表的都會(huì)碰到的問(wèn)題–跟隨鼠標(biāo)顯示值,在QCustomPlot里非常簡(jiǎn)單,它早就給出了解決方案-QCPItemTracer

代碼片段和文件信息
void?MEMSCurve::MEMSCurve()
{
//跟蹤器
m_xTracer?=?new?MyTracer(m_custPlot?MyTracer::XAxisTracer?m_custPlot);//x軸
m_tracer1?=?new?MyTracer(m_custPlot?MyTracer::DataTracer?m_custPlot);
m_tracer2?=?new?MyTracer(m_custPlot?MyTracer::DataTracer?m_custPlot);
m_lineTracer?=?new?MyTracer(m_custPlot?MyTracer::CrossLine?m_custPlot);//直線
connect(m_custPlot?SIGNAL(mouseMove(QMouseEvent*))?this?SLOT(myMouseMoveEvent(QMouseEvent*)));
}
void?MEMSCurve::myMouseMoveEvent(QMouseEvent*?event)
{
int?x_pos?=?event->pos().x();
int?y_pos?=?event->pos().y();
float?x_val?=?EMSTabPage.m_plot.m_custPlot->xAxis->pixelToCoord(x_pos);
float?y_val?=?EMSTabPage.m_plot.m_custPlot->yAxis->pixelToCoord(y_pos);
EMSTabPage.m_plot.m_xTracer->updatePosition(x_val?y_val);
auto?iter?=?EMSTabPage.m_plot.m_custPlot->graph(0)->data()->findBegin(x_val);
double?value1?=?iter->mainValue();
iter?=?EMSTabPage.m_plot.m_custPlot->graph(1)->data()->findBegin(x_val);
double?value2?=?iter->mainValue();
EMSTabPage.m_plot.m_tracer1->updatePosition(x_val?value1);
EMSTabPage.m_plot.m_tracer2->updatePosition(x_val?value2);
EMSTabPage.m_plot.m_lineTracer->updatePosition(x_val?y_val);
ui->custPlot->replot();//曲線重繪
}
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???????1238??2018-04-16?16:26??MyTracer\main.cpp
?????文件???????4471??2018-04-16?16:22??MyTracer\MyTracer.cpp
?????文件????????977??2018-04-16?15:56??MyTracer\MyTracer.h
?????文件????????137??2018-04-16?16:30??MyTracer\說(shuō)明.txt
?????文件??????77676??2018-04-16?16:27??MyTracer\運(yùn)行結(jié)果.PNG
?????目錄??????????0??2018-04-16?16:28??MyTracer
-----------?---------??----------?-----??----
????????????????84499????????????????????6
- 上一篇:不掉血源碼
- 下一篇:usbview 的vs2005工程
評(píng)論
共有 條評(píng)論