Hello everyone! I have a special class for building graphs, but when i want to add it on scrollArea, i have some issues. Graphs are very small and if i want to print 50 graphs, i will see something like that: "They are pressed against each other and nothing is visible, but i want each graph to be with normal height and stretch across the entire width of the screen.
Graph class
#include "graphbuilder.h" GraphBuilder::GraphBuilder(QWidget* parent) : QWidget(parent) { _customPlot = new QCustomPlot(this); } GraphBuilder::~GraphBuilder() { delete _customPlot; } void GraphBuilder::build(QMap<QString, QVector<double>>& position, const QString& header, const QVector<QTime>& time) { QVector<double> timeData; QVector<double> positionData; for (int i = 0; i < time.size(); ++i) { timeData.append(time[i].msecsSinceStartOfDay()); } positionData = position[header]; _customPlot->addGraph(); _customPlot->graph()->setData(timeData, positionData); _customPlot->graph()->setPen(QPen(QColor("green"))); QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime); dateTicker->setDateTimeFormat("hh:mm:ss.zzz"); _customPlot->xAxis->setTicker(dateTicker); _customPlot->xAxis->setLabel("Time"); _customPlot->yAxis->setLabel("Position"); QCPTextElement *title = new QCPTextElement(_customPlot); title->setText(header); title->setFont(QFont("sans", 12, QFont::Bold)); _customPlot->plotLayout()->insertRow(0); _customPlot->plotLayout()->addElement(0, 0, title); _customPlot->setInteraction(QCP::iRangeZoom, true); _customPlot->setInteraction(QCP::iRangeDrag, true); _customPlot->setFixedSize(1200, 900); // _customPlot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); _customPlot->rescaleAxes(); _customPlot->replot(); }
void MainWindow::printGraph() { QMap<QString, QVector<double>> position = controller->getPosition(); // qDebug() << position; QStringList headers = controller->getHeaders(); // qDebug() << headers; QVector<QTime> time = controller->getTime(); // qDebug() << time; for (int i = 0; i < 50; ++i) { GraphBuilder* graph = new GraphBuilder(); graph->build(position, headers[3], time); ui->graphic->addWidget(graph); } }