QCustomPlot中用直線標示曲線的值

2021-09-22 18:30:53 字數 1372 閱讀 3363

摘自:

qcustomplot是乙個非常好用的曲線控制項,詳細的介紹可以參見:

要實現隨著滑鼠的移動,顯示一條豎線並標明曲線的數值。

原始碼是參考

新增了一些個性化。

一、使用

1.在初始化函式中new幾個tracer,分別是xaxistracer,datatracer,crossline。

//***

plot.m_xtracer = new mytracer(plot.m_custplot, mytracer::xaxistracer, plot.m_custplot);//x軸

plot.m_tracer1 = new mytracer(plot.m_custplot, mytracer::datatracer, plot.m_custplot);

plot.m_tracer2 = new mytracer(plot.m_custplot, mytracer::datatracer, plot.m_custplot);

plot.m_linetracer = new mytracer(plot.m_custplot, mytracer::crossline, plot.m_custplot);//直線

2.新增對滑鼠移動事件的響應

connect(m_custplot, signal(mousemove(qmouseevent*)), this, slot(mymousemoveevent(qmouseevent*)));

3.實現響應函式mymousemoveevent

其中pixeltocoord將滑鼠的位置轉換成具體的座標系下的值

m_plot.m_custplot->graph(0)->data()->findbegin(x_val);獲取第一條曲線上相應的值。

emstabpage.m_plot.m_tracer1->updateposition(x_val, value1);更新tracer的值

最後replot()就可以了。

void memscurve::mymousemoveevent(qmouseevent* event)

**實現:

在mytracer中主要看updateposition這個函式。

void mytracer::updateposition(double xvalue, double yvalue)

if (yvalue > plot->yaxis->range().upper)

yvalue = plot->yaxis->range().upper;

switch (type)

case yaxistracer:

case datatracer:

case crossline:

default:

break;

}

QcustomPlot 配置使用

1.qt 然後在pro裡面新增 qt core gui greaterthan qt major vesion,4 qt widgets printsupport qt 5.0以上版本支援列印就可以直接使用了 可以在ui design裡面 新增widget控制項然後右鍵提公升為qcustomplot...

QChart與QCustomPlot簡單運用

qchart的使用 條件 需要在.pro檔案新增qt charts 四個標頭檔案的作用 include 類似於畫筆 include 類似於畫布 include 類 series 是用來新增資料的物件 可以理解為乙個集合 include 用來自定義圖表中的x,y座標軸 定義了五個物件qchartvie...

QCustomPlot 簡單使用 一

根據官方例項修改,主要實現如上效果,qcustomplot 繪圖的座標軸正常有四個 橫軸下邊 xaxis 預設顯示,橫軸上邊 xaxis2 縱軸左邊 yaxis 預設顯示,縱軸右邊邊 yaxis2 demoname quadratic demo generate some data qvectorx...