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

yongxingongchen yongxingongchen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想实现曲线范围性的拖动,如拖动横坐标-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));
}
...全文
评论 6
收藏 已收藏
分享
返回顶部
yongxingongchen
C++ 语言 65,212 成员 250,513 内容