QT insert widget inside an other widget

后端 未结 1 1979
南笙
南笙 2021-01-22 22:16

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

相关标签:
1条回答
  • 2021-01-22 22:40

    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);
    }
    
    0 讨论(0)
提交回复
热议问题