QCustomPlot 对鼠标悬停的轴进行缩放
2022/2/27 23:29:31
本文主要是介绍QCustomPlot 对鼠标悬停的轴进行缩放,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
功能
当鼠标悬停在某一个轴上时,滚动鼠标滚轮,可实现对该轴进行缩放,其他轴不变。
PRPDView 集成自 QCustomPlot
初始化
void PRPDView::creatInit() { this->yAxis2->setVisible(true);//显示x轴2 this->yAxis2->setRange(0,10); // this->axisRect()->setupFullAxesBox(true);//会影响轴yAxis2显示 this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |QCP::iSelectAxes); this->xAxis->setRange(0,360); //相位 0~360 mTemplateCurve = addGraph(this->xAxis,this->yAxis); mScatterCurve = addGraph(this->xAxis,this->yAxis2); QPen drawPen; drawPen.setColor(Qt::blue); drawPen.setWidth(2); mTemplateCurve->setPen(drawPen); drawPen.setColor(Qt::red); drawPen.setWidth(4); mScatterCurve->setPen(drawPen); mScatterCurve->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle)); mScatterCurve->setLineStyle(QCPGraph::lsNone); this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignHCenter); // 对齐于QCPAxisRect中间的顶部 connect(this, &PRPDView::mouseWheel, this, &PRPDView::slot_mouseWheel); }
生成模拟数据
void PRPDView::setDemo() { //生成模板图 QVector<double> xPoints(360),yPoints(360); for(int x0 = 0;x0 < 361 ;x0++){ xPoints.append(x0); yPoints.append(qSin((double)x0/360. * 2 * Pi) * 1000); } this->templateGraph()->setData(xPoints,yPoints); //生成随机散点图 xPoints.clear(); yPoints.clear(); for(int cnt = 0;cnt < 5000;cnt++){ xPoints.append(QRandomGenerator::global()->bounded(1.) * 360.); yPoints.append(QRandomGenerator::global()->bounded(1.) * 10.); } this->scatterGtaph()->setData(xPoints,yPoints); this->rescaleValueAxisinRange(); this->replot(); }
槽函数
void PRPDView::slot_mouseWheel() { QList<QCPAxis*> axes; if (xAxis->axisRect()->rect().contains(QCursor::pos())){ axes<<xAxis; axisRect()->setRangeZoomAxes(axes); axisRect()->setRangeZoom(xAxis->orientation()); } else if (yAxis->axisRect()->rect().contains(QCursor::pos())){ axes<<yAxis; axisRect()->setRangeZoomAxes(axes); axisRect()->setRangeZoom(yAxis->orientation()); } else if(yAxis2->axisRect()->rect().contains(QCursor::pos())){ axes<<yAxis2; axisRect()->setRangeZoomAxes(axes); axisRect()->setRangeZoom(yAxis2->orientation()); } else{ axes<<yAxis<<xAxis<<yAxis2; axisRect()->setRangeZoomAxes(axes); axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); } }
main
PRPDView *view = new PRPDView(); view->setAttribute(Qt::WA_DeleteOnClose); view->setDemo(); view->show();
这篇关于QCustomPlot 对鼠标悬停的轴进行缩放的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升
- 2024-05-08代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!