qt charts in qgridlayout
-
Hi All,
i wanted to embedd example: http://doc.qt.io/qt-5/qtcharts-linechart-example.html into qtgridlayout:
here is constructor of QMainWindow:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); lcdNumber = new QLCDNumber(); lcdNumber_2 = new QLCDNumber(); progressBar = new QProgressBar(); lcdNumber->display("wait..."); m_progress = 0; progressBar->setMinimum(0); progressBar->setMaximum(59); progressBar->setValue(m_progress); TempChart *tChart = new TempChart(); ui->gridLayout->addWidget(lcdNumber, 0, 0); ui->gridLayout->addWidget(lcdNumber_2, 0, 1); ui->gridLayout->addWidget(tChart, 1, 0, 1, 2); tChart->show(); }
and constructor of TempChart:
TempChart::TempChart(QWidget *parent) : QWidget(parent) { QLineSeries *series = new QLineSeries(); series->append(0, 6); series->append(2, 4); series->append(3, 8); series->append(7, 4); series->append(10, 5); QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(series); chart->createDefaultAxes(); chart->setTitle("Simple line chart example"); chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); }
Once i exectue it im able to see lcdNumber and lcdNumber_2 on display, however im not able to see my chart on rest of screen. Any ideas why?
thx in advance for support
s. -
@sieciech
because in your TempChart class you just create a QChartView widget without a parent nor do you add it to a layout. -
Thx!!!!
in fact when i changed:
ui->gridLayout->addWidget(tChart, 1, 0, 1, 2);
into:
ui->gridLayout->addWidget(tChart-> chartView, 1, 0, 1, 2);
and chart was present!
However lcd displays stopped recating on: lcdNumber->display(value), where value shall be updated each second....( previously, without chart it worked as it should). Any ideas?regards
s. -
@sieciech
i doubt that just adding it to a layout causes this issue.
But you also haven't posted any code how the updating of the QLCDNumber widgets actually works.