-
大小: 397KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-06-14
- 語言: 其他
- 標簽: qt??QCustomPlot??
資源簡介
該資源是qt用QCustomPlot實現(xiàn)鼠標實時回調(diào)xy軸數(shù)據(jù)并顯示在曲線內(nèi)的實現(xiàn)代碼,詳細請參考我的博客文章

代碼片段和文件信息
#include?“mytracer.h“
myTracer::myTracer(QCustomPlot?*_plot?QCPGraph?*_graph?TracerType?_type)?:?plot(_plot)
????graph(_graph)
????type(_type)
????visible(false)
{
????if?(plot)
????{
????????tracer?=?new?QCPItemTracer(plot);
????????tracer->setstyle(QCPItemTracer::tsCircle);//可以選擇設置追蹤光標的樣式,這個是小十字,還有大十字,圓點等樣式
????????tracer->setPen(QPen(Qt::green));//設置tracer的顏色綠色
????????//tracer->setPen(graph->pen());//設置tracer的顏色跟曲線
????????tracer->setBrush(QPen(Qt::green).color());
????????tracer->setSize(6);
????????label?=?new?QCPItemText(plot);
????????label->setlayer(“overlay“);
????????label->setClipToAxisRect(false);
????????label->setPadding(QMargins(5?5?5?5));
????????label->position->setParentAnchor(tracer->position);
????????label->setFont(QFont(“宋體“?10));
????????arrow?=?new?QCPItemLine(plot);
????????arrow->setlayer(“overlay“);
????????//arrow->setPen(graph->pen());//設置箭頭的顏色跟隨曲線
????????arrow->setPen(QPen(Qt::red));//設置箭頭的顏色紅色
????????arrow->setClipToAxisRect(false);
????????arrow->setHead(QCPLineEnding::esSpikeArrow);
????????switch?(type)?{
????????case?XAxisTracer:
????????{
????????????tracer->position->setTypeX(QCPItemPosition::ptPlotCoords);
????????????tracer->position->setTypeY(QCPItemPosition::ptAxisRectRatio);
????????????label->setBrush(QBrush(QColor(244?244?244?100)));
????????????label->setPen(QPen(Qt::black));
????????????label->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
????????????arrow->end->setParentAnchor(tracer->position);
????????????arrow->start->setParentAnchor(arrow->end);
????????????arrow->start->setCoords(20?0);//偏移量
????????????break;
????????}
????????case?YAxisTracer:
????????{
????????????tracer->position->setTypeX(QCPItemPosition::ptAxisRectRatio);
????????????tracer->position->setTypeY(QCPItemPosition::ptPlotCoords);
????????????label->setBrush(QBrush(QColor(244?244?244?100)));
????????????label->setPen(QPen(Qt::black));
????????????label->setPositionAlignment(Qt::AlignRight|Qt::AlignHCenter);
????????????arrow->end->setParentAnchor(tracer->position);
????????????arrow->start->setParentAnchor(label->position);
????????????arrow->start->setCoords(-20?0);//偏移量
????????????break;
????????}
????????case?DataTracer:
????????{
????????????tracer->position->setTypeX(QCPItemPosition::ptPlotCoords);
????????????tracer->position->setTypeY(QCPItemPosition::ptPlotCoords);
????????????label->setBrush(QBrush(QColor(244?244?244?150)));
????????????//label->setPen(graph->pen());//邊框跟隨曲線顏色
????????????label->setPen(QPen(Qt::red));//邊框紅色
????????????label->setPositionAlignment(Qt::AlignLeft|Qt::AlignVCenter);
????????????arrow->end->setParentAnchor(tracer->position);
????????????arrow->start->setParentAnchor(arrow->end);
????????????arrow->start->setCoords(25?0);
????????????break;
????????}
????????default:
????????????break;
????????}
????????setVisible(false);
????}
}
myTracer::~myTracer()
{
????if?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4732??2019-07-10?00:44??MyTracer\mytracer.cpp
?????文件???????1109??2019-07-10?00:29??MyTracer\mytracer.h
?????文件?????851667??2015-12-22?08:02??QCustomPlot\qcustomplot-一版.cpp
?????文件?????149282??2015-12-22?08:02??QCustomPlot\qcustomplot-一版.h
?????文件????1118717??2017-09-04?08:02??QCustomPlot\qcustomplot.cpp
?????文件?????266925??2017-09-04?08:02??QCustomPlot\qcustomplot.h
?????目錄??????????0??2019-07-10?09:12??MyTracer
?????目錄??????????0??2019-07-10?09:12??QCustomPlot
-----------?---------??----------?-----??----
??????????????2392432????????????????????8
- 上一篇:京東商城數(shù)據(jù)模型.rar
- 下一篇:超級全面的完整停用詞表
評論
共有 條評論