qcustomplot如何范围性拖动曲线X轴等

yongxingongchen 2016-04-22 04:56:21
我想实现曲线范围性的拖动,如拖动横坐标-10到10,纵坐标-10到10,请问下如何实现,我看了下好像有个函数是
setRangeDragAxes(),感觉可以用,但是没实现出来,各位大神有没有想法,最好给出大致代码,谢谢
void MainWindow::setupSimpleDemo(QCustomPlot *customPlot)
{
demoName = "Simple Demo";

// add two new graphs and set their look:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
// generate some points of data (y0 for first, y1 for second graph):
QVector<double> x(250), y0(250), y1(250);
for (int i=0; i<250; ++i)
{
x[i] = i;
y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
y1[i] = qExp(-i/150.0); // exponential envelope
}
customPlot->graph(0)->setData(x, y0);
customPlot->graph(1)->setData(x, y1);
// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
customPlot->graph(0)->rescaleAxes();
// same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
customPlot->graph(1)->rescaleAxes(true);
// Note: we could have also just called customPlot->rescaleAxes(); instead
// Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
// QPointer<QCPAxis> mColorAxis;
// mColorAxis.data()
// customPlot->axisRect()->setRangeDragAxes(customPlot->axisRect()->axis(QCPAxis::atBottom),customPlot->axisRect()->axis(QCPAxis::atLeft));
}
...全文
833 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32755907 2017-11-13
  • 打赏
  • 举报
回复
楼主,你解决了吗,我也遇到了这个问题,求指点
小灸舞 2016-04-25
  • 打赏
  • 举报
回复
用过
yongxingongchen 2016-04-25
  • 打赏
  • 举报
回复
没有人用过qcustomPlot第三方库区写过曲线的吗??
yongxingongchen 2016-04-22
  • 打赏
  • 举报
回复
要能找到的话,我已经找到了,网上好像没有,能给点具体的代码吗??
yongxingongchen 2016-04-22
  • 打赏
  • 举报
回复
自己帮顶下,求大神指导,谢谢

64,687

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧