没有合适的资源?快使用搜索试试~ 我知道了~
首页QCustomPlot设置游标详细笔记.docx
QCustomPlot设置游标详细笔记.docx
1星 需积分: 48 99 下载量 113 浏览量
更新于2023-03-16
评论 4
收藏 70KB DOCX 举报
利用QCustomPlot,完全实现示波器中的X和Y轴两条迹线,添加图注说明,设置数据说明跟随鼠标移动。
资源详情
资源评论
资源推荐
QCustomPlot 设置游标详细笔记
在 QT 下开发虚拟示波器程序时,需要用到曲线显示控件,开源的有 QCustomPlot 和
QWT,其中 QCustomPlot 可以直接利用其源码,而不需要使用链接库的方式,因此,得到
了大量的应用,为了简化,我使用了 QCustomPlot 1.3.0 的源代码并进行了修改实现完整的
功能。
1、X 轴和 Y 轴坐标迹线
常见示波器上,可以设置 X 轴和 Y 轴坐标迹线并且可以移动。为此,在借鉴网上代码
(hp://www.manongjc.com/arcle/22306.html 基于 QCustomPlot 绘图,鼠标跟随动态显示
曲线上的点的值)基础上,定义 ScopeTraceLine 类,与网上提供代码相比,增加了代表位
置的坐标值变量和获取属性函数,并做出了相应的修改。
///
/// rief The ScopeCrossLine class:用于显示鼠标移动过程中的鼠标位置的直线
///
class ScopeTraceLine : public QObject
{
public:
explicit ScopeTraceLine(QCustomPlot *_plot, LineType _type = VercalLine, QObject
*parent = Q_NULLPTR);
~ScopeTraceLine();
void initLine();
void updatePosion(double xValue, double yValue);
void setSelected(bool selected);
void setVisible(bool vis);
LineType GetType()const{return m_type;}
double getPosionX()const{return m_xValue;}
double getPosionY()const{return m_yValue;}
protected:
bool m_visible;//是否可见
LineType m_type;//类型
QCustomPlot *m_plot;//图表
QCPItemStraightLine *m_lineV; //垂直线
QCPItemStraightLine *m_lineH; //水平线
double m_xValue;
double m_yValue;
};
具体实现函数如下:
ScopeTraceLine::ScopeTraceLine(QCustomPlot *_plot, LineType _type, QObject *parent)
: QObject(parent),
m_type(_type),
m_plot(_plot)
{
m_lineV = Q_NULLPTR;
m_lineH = Q_NULLPTR;
m_xValue= -999;
m_yValue= -999;
initLine();
}
ScopeTraceLine::~ScopeTraceLine()
{
if(m_plot)
{
if (m_lineV)
m_plot->removeItem(m_lineV);
if (m_lineH)
m_plot->removeItem(m_lineH);
}
}
void ScopeTraceLine::initLine()
{
if(m_plot)
{
QPen linesPen(Qt::green, 1, Qt::DashLine);
if(VercalLine == m_type || Both == m_type)
{
m_lineV = new QCPItemStraightLine(m_plot);//垂直线
m_lineV->setLayer("overlay");
m_lineV->setPen(linesPen);
m_lineV->setClipToAxisRect(true);
m_lineV->point1->setCoords(0, 0);
m_lineV->point2->setCoords(0, 0);
}
if(HorizonLine == m_type || Both == m_type)
{
m_lineH = new QCPItemStraightLine(m_plot);//水平线
m_lineH->setLayer("overlay");
m_lineH->setPen(linesPen);
m_lineH->setClipToAxisRect(true);
m_lineH->point1->setCoords(0, 0);
m_lineH->point2->setCoords(0, 0);
}
}
}
void ScopeTraceLine::setVisible(bool vis)
{
if(m_lineV)
m_lineV->setVisible(vis);
if(m_lineH)
m_lineH->setVisible(vis);
}
void ScopeTraceLine::setSelected(bool selected)
{
QPen linesPen(Qt::green, 1, Qt::DashLine);
if(selected)
linesPen.setColor(Qt::red);
if(VercalLine == m_type || Both == m_type)
{
if(Q_NULLPTR != m_lineV)
m_lineV->setPen(linesPen);
}
if(HorizonLine == m_type || Both == m_type)
{
if(Q_NULLPTR != m_lineH)
m_lineH->setPen(linesPen);
}
}
void ScopeTraceLine::updatePosion(double xValue, double yValue)
{
m_xValue = xValue;
m_yValue = yValue;
if(VercalLine == m_type || Both == m_type)
{
if(m_lineV)
{
m_lineV->point1->setCoords(xValue, m_plot->yAxis->range().lower);
m_lineV->point2->setCoords(xValue, m_plot->yAxis->range().upper);
}
}
if(HorizonLine == m_type || Both == m_type)
{
if(m_lineH)
{
剩余11页未读,继续阅读
qq_39621571
- 粉丝: 43
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- stc12c5a60s2 例程
- Android通过全局变量传递数据
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1