我用qt Creator创建了一个UI,在这个UI中只有一个按钮和一个小部件(我们分别称之为button和char_container); 我需要在chart_container内以编程方式添加chartview。 我没有更改默认布局。QT在其他小部件中插入小部件
我尝试下面的代码,但它不工作:
void MainWindow::button_slot(){
QtCharts::QChart *chart = new QtCharts::QChart();
QtCharts::QChartView *chartView = new QtCharts::QChartView(chart);
chartView->setParent(ui->chart_container);
this.repaint();
}
您仍然需要将您的chartview添加到MainWindow(仅设置父级是不够的,AFAIK)。 – dbrank0