【发布时间】:2018-03-08 19:38:57
【问题描述】:
我用 qt Creator 创建了一个 UI,在这个 UI 中只有一个按钮和一个小部件(我们分别称它为 button 和 char_container); 我需要在chart_container 中以编程方式添加图表视图。 我没有更改默认布局。
我尝试了以下代码,但它不起作用:
void MainWindow::button_slot(){
QtCharts::QChart *chart = new QtCharts::QChart();
QtCharts::QChartView *chartView = new QtCharts::QChartView(chart);
chartView->setParent(ui->chart_container);
this.repaint();
}
【问题讨论】:
-
您仍然需要将您的图表视图添加到 MainWindow(仅设置父级是不够的,AFAIK)。