Hello!
I want to create a program, which plots graph. I am using QtCharts (thanks God its available in Qt 5.7). The idea is: there is a Widget (inher. from QWidget), I push a button and create new QWidget - window and there is plot, which is build already.
But I want to re-plot it, so I put the int-number in QLineEdit on my new QWidget and I want the graph to re-plot, but the problem is that I already created a QWidget and graph is already there..
How can I pass parameter to new QWidget in order to re-plot my graph there..?
This is code:
void Widget::plotAGraph()
{
horizontal->addWidget(ok2);
horizontal->addWidget(plotNumber);
horizontal->addWidget(stepp);
QScatterSeries *series0 = new QScatterSeries();
// series0->setName("Первое Ñечение");
series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
series0->setMarkerSize(15.0);
//here is parameter of my graph__and parameter step I want to change___
int a=1;
for(int i=step;i<step+50;i++){
series0->append(a, obj.A[i]);
a++;
}
//_______________________________________________________________
QChart *chart=new QChart;
chart->addSeries(series0);
chart->setTitle("Сечение в первом разрезе");
// chart->axisX()->setRange(0,90);
// chart->axisY()->setRange(0,100);
chart->createDefaultAxes();
chart->axisX()->setRange(0,90);
chart->axisY()->setRange(0,100);
QChartView *chartView = new QChartView(chart);
chartView
->setRenderHint
(QPainter::Antialiasing);
vertical-> addWidget(chartView);
vertical-> addLayout(horizontal);
newWindow-> setLayout(vertical);
newWindow->setGeometry(300,150,0,0);
newWindow->resize(600,500);
newWindow->show();
connect(ok2,SIGNAL(clicked(bool)),newWindow,SLOT(replot()));
}
void Widget::replot()
{
//Doesnt work
// int step = plotNumber.text().toInt();
// how can I pass a parameter step in Loop in slot plotGraph and then to re-plot it all ?
}
void Widget::plotAGraph()
{
QVBoxLayout *vertical = new QVBoxLayout();
QHBoxLayout *horizontal = new QHBoxLayout();
QPushButton *ok2 = new QPushButton("Close");
QLineEdit *plotNumber = new QLineEdit("Step Number");
QSlider *stepp=new QSlider(Qt::Horizontal);
horizontal->addWidget(ok2);
horizontal->addWidget(plotNumber);
horizontal->addWidget(stepp);
QScatterSeries *series0 = new QScatterSeries();
// series0->setName("Первое Ñечение");
series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
series0->setMarkerSize(15.0);
//here is parameter of my graph__and parameter step I want to change___
int a=1;
for(int i=step;i<step+50;i++){
series0->append(a, obj.A[i]);
a++;
}
//_______________________________________________________________
QChart *chart=new QChart;
chart->addSeries(series0);
chart->setTitle("Сечение в первом разрезе");
// chart->axisX()->setRange(0,90);
// chart->axisY()->setRange(0,100);
chart->createDefaultAxes();
chart->axisX()->setRange(0,90);
chart->axisY()->setRange(0,100);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
QWidget *newWindow=new QWidget();
vertical-> addWidget(chartView);
vertical-> addLayout(horizontal);
newWindow-> setLayout(vertical);
newWindow->setGeometry(300,150,0,0);
newWindow->resize(600,500);
newWindow->show();
connect(ok2,SIGNAL(clicked(bool)),newWindow,SLOT(replot()));
}
void Widget::replot()
{
//Doesnt work
// int step = plotNumber.text().toInt();
// how can I pass a parameter step in Loop in slot plotGraph and then to re-plot it all ?
}
To copy to clipboard, switch view to plain text mode
in file Widget.cpp I created object of class calculation and named it obj.
In the class there is an Array A
I create a plot:
for(int i=step;i<step+50;i++){
series0->append(a, obj.A[i]);
a++;
}
for(int i=step;i<step+50;i++){
series0->append(a, obj.A[i]);
a++;
}
To copy to clipboard, switch view to plain text mode
а - step along x
Ð[i] - value accord. to the step
Thanks in advance!
Bookmarks