Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "qcustomplot.h"
- #include "QColorDialog"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- q = QColor("green");
- // add two new graphs and set their look:
- QVector<double> x1 = {1,2,2,1};
- QVector<double> y1 = {1,2,1,1};
- /* QVector<double> x2 = {1,1};
- QVector<double> y2 = {1,3};*/
- // create and configure plottables:
- QCPGraph *graph1 = ui->customPlot->addGraph();
- graph1->setData(x1, y1);
- graph1->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssSquare, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
- graph1->setPen(QPen(QColor(120, 120, 120), 2));
- /* QCPGraph *graph2 = ui->customPlot->addGraph();
- graph2->setData(x2, y2);
- graph2->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
- graph2->setPen(QPen(QColor(120, 120, 120), 2));*/
- // move bars above graphs and grid below bars:
- ui->customPlot->addLayer("abovemain", ui->customPlot->layer("main"), QCustomPlot::limAbove);
- ui->customPlot->addLayer("belowmain", ui->customPlot->layer("main"), QCustomPlot::limBelow);
- graph1->setLayer("abovemain");
- ui->customPlot->xAxis->grid()->setLayer("belowmain");
- ui->customPlot->yAxis->grid()->setLayer("belowmain");
- // set some pens, brushes and backgrounds:
- ui->customPlot->xAxis->setBasePen(QPen(Qt::white, 1));
- ui->customPlot->yAxis->setBasePen(QPen(Qt::white, 1));
- ui->customPlot->xAxis->setTickPen(QPen(Qt::white, 1));
- ui->customPlot->yAxis->setTickPen(QPen(Qt::white, 1));
- ui->customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1));
- ui->customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1));
- ui->customPlot->xAxis->setTickLabelColor(Qt::white);
- ui->customPlot->yAxis->setTickLabelColor(Qt::white);
- ui->customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
- ui->customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
- ui->customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
- ui->customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
- ui->customPlot->xAxis->grid()->setSubGridVisible(true);
- ui->customPlot->yAxis->grid()->setSubGridVisible(true);
- ui->customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
- ui->customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen);
- ui->customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
- ui->customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
- // ui->customPlot->xAxis->setLabel("X");
- //ui->customPlot->yAxis->setLabel("Y");
- QLinearGradient plotGradient;
- plotGradient.setStart(0, 0);
- plotGradient.setFinalStop(0, 350);
- plotGradient.setColorAt(0, QColor(80, 80, 80));
- plotGradient.setColorAt(1, QColor(50, 50, 50));
- ui->customPlot->setBackground(plotGradient);
- QLinearGradient axisRectGradient;
- axisRectGradient.setStart(0, 0);
- axisRectGradient.setFinalStop(0, 350);
- axisRectGradient.setColorAt(0, QColor(80, 80, 80));
- axisRectGradient.setColorAt(1, QColor(30, 30, 30));
- ui->customPlot->axisRect()->setBackground(axisRectGradient);
- ui->customPlot->rescaleAxes();
- ui->customPlot->yAxis->setRange(0, 2);
- ui->customPlot->setInteraction(QCP::iRangeZoom,true);
- ui->customPlot->setInteraction(QCP::iRangeDrag,true);
- q = QColorDialog::getColor(Qt::white,this, "Color");
- graph1->setBrush(QBrush(q));
- //graph3->setBrush(QBrush(q));
- // graph4->setChannelFillGraph(graph3);
- // graph3->setBrush(QBrush(q));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement