I\'ve created an UI with qt Creator,in this UI there is just a button and a widget (let\'s call it respectively button and char_container); I need to add a chartview programmati
The best way to add a widget inside another is to use a layout, as I show below:
//on constructor
ui->chart_container->setLayout(new QVBoxLayout);
void MainWindow::button_slot()
{
QtCharts::QChart *chart = new QtCharts::QChart();
QtCharts::QChartView *chartView = new QtCharts::QChartView(chart, ui->chart_container);
ui->chart_container->layout()->addWidget(chartView);
}