Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "qcustomplot.h"
  4. #include "QColorDialog"
  5. MainWindow::MainWindow(QWidget *parent) :
  6.     QMainWindow(parent),
  7.     ui(new Ui::MainWindow)
  8. {
  9.     ui->setupUi(this);
  10.         q = QColor("green");
  11.     // add two new graphs and set their look:
  12.  
  13.  
  14.      QVector<double> x1 = {1,2,2,1};
  15.        QVector<double> y1 = {1,2,1,1};
  16.  
  17.  /*   QVector<double> x2 = {1,1};
  18.         QVector<double> y2 = {1,3};*/
  19.  
  20.     // create and configure plottables:
  21.     QCPGraph *graph1 = ui->customPlot->addGraph();
  22.     graph1->setData(x1, y1);
  23.     graph1->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssSquare, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
  24.     graph1->setPen(QPen(QColor(120, 120, 120), 2));
  25.  
  26.   /* QCPGraph *graph2 = ui->customPlot->addGraph();
  27.     graph2->setData(x2, y2);
  28.     graph2->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
  29.     graph2->setPen(QPen(QColor(120, 120, 120), 2));*/
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.     // move bars above graphs and grid below bars:
  38.     ui->customPlot->addLayer("abovemain", ui->customPlot->layer("main"), QCustomPlot::limAbove);
  39.     ui->customPlot->addLayer("belowmain", ui->customPlot->layer("main"), QCustomPlot::limBelow);
  40.     graph1->setLayer("abovemain");
  41.     ui->customPlot->xAxis->grid()->setLayer("belowmain");
  42.     ui->customPlot->yAxis->grid()->setLayer("belowmain");
  43.  
  44.     // set some pens, brushes and backgrounds:
  45.     ui->customPlot->xAxis->setBasePen(QPen(Qt::white, 1));
  46.     ui->customPlot->yAxis->setBasePen(QPen(Qt::white, 1));
  47.     ui->customPlot->xAxis->setTickPen(QPen(Qt::white, 1));
  48.     ui->customPlot->yAxis->setTickPen(QPen(Qt::white, 1));
  49.     ui->customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1));
  50.     ui->customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1));
  51.     ui->customPlot->xAxis->setTickLabelColor(Qt::white);
  52.     ui->customPlot->yAxis->setTickLabelColor(Qt::white);
  53.     ui->customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
  54.     ui->customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
  55.     ui->customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
  56.     ui->customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
  57.     ui->customPlot->xAxis->grid()->setSubGridVisible(true);
  58.     ui->customPlot->yAxis->grid()->setSubGridVisible(true);
  59.     ui->customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
  60.     ui->customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen);
  61.     ui->customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
  62.     ui->customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
  63.    // ui->customPlot->xAxis->setLabel("X");
  64.      //ui->customPlot->yAxis->setLabel("Y");
  65.     QLinearGradient plotGradient;
  66.     plotGradient.setStart(0, 0);
  67.     plotGradient.setFinalStop(0, 350);
  68.     plotGradient.setColorAt(0, QColor(80, 80, 80));
  69.     plotGradient.setColorAt(1, QColor(50, 50, 50));
  70.     ui->customPlot->setBackground(plotGradient);
  71.     QLinearGradient axisRectGradient;
  72.     axisRectGradient.setStart(0, 0);
  73.     axisRectGradient.setFinalStop(0, 350);
  74.     axisRectGradient.setColorAt(0, QColor(80, 80, 80));
  75.     axisRectGradient.setColorAt(1, QColor(30, 30, 30));
  76.     ui->customPlot->axisRect()->setBackground(axisRectGradient);
  77.  
  78.     ui->customPlot->rescaleAxes();
  79.     ui->customPlot->yAxis->setRange(0, 2);
  80.     ui->customPlot->setInteraction(QCP::iRangeZoom,true);
  81.     ui->customPlot->setInteraction(QCP::iRangeDrag,true);
  82.       q = QColorDialog::getColor(Qt::white,this, "Color");
  83.     graph1->setBrush(QBrush(q));
  84.      //graph3->setBrush(QBrush(q));
  85.   //   graph4->setChannelFillGraph(graph3);
  86.    //  graph3->setBrush(QBrush(q));
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement