本文主要是介绍Qt 小例子学习42 - qcustomplot 边界、填充渐变,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt 小例子学习42 - qcustomplot 边界、填充渐变
#include "qcustomplot.h"
#include <QApplication>
#include <QTimer>
int main(int argc, char *argv[])
{QApplication a(argc, argv);QCustomPlot *_myPlot = new QCustomPlot;_myPlot->resize(640, 480);// some dataQVector<double> x;QVector<double> y;for (int point = 0; point < 100; point++){x << point;y << 80 * qSin(point * 0.1);}QCPGraph *newCurve = new QCPGraph(_myPlot->xAxis, _myPlot->yAxis);newCurve->addData(x, y);QBrush shadowBrush(QColor(0, 0, 0), Qt::Dense7Pattern);newCurve->setBrush(shadowBrush);QCPGraph *minGraph = new QCPGraph(_myPlot->xAxis, _myPlot->yAxis);newCurve->setChannelFillGraph(minGraph);QObject::connect(_myPlot->xAxis,static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged),[_myPlot, minGraph](const QCPRange & newRange){minGraph->setData(QVector<double> {newRange.lower, newRange.upper},QVector<double> {_myPlot->yAxis->range().lower,_myPlot->yAxis->range().lower});});QObject::connect(_myPlot->yAxis,static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged),[_myPlot, minGraph](const QCPRange & newRange){minGraph->setData(QVector<double> {_myPlot->xAxis->range().lower,_myPlot->xAxis->range().upper},QVector<double> {newRange.lower, newRange.lower});});// test_myPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |QCP::iSelectAxes | QCP::iSelectLegend |QCP::iSelectPlottables);QTimer timer;QObject::connect(&timer, &QTimer::timeout, [&_myPlot](){QCPRange range = _myPlot->yAxis->range();range.lower -= 1;_myPlot->yAxis->setRange(range);_myPlot->replot();});timer.start(100);_myPlot->rescaleAxes();_myPlot->show();return a.exec();
}
这篇关于Qt 小例子学习42 - qcustomplot 边界、填充渐变的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!