Properly changing the displayed chart in a QChartView
-
wrote on 22 Apr 2022, 05:15 last edited by
I am trying to change the displayed chart in a QChartView, but each time the program fails in some form.
void MainWindow::updateRollResult(QString rollResult, QChart* chart){ ui->rollResultLabel->setText("Sum of all dice rolls: " + rollResult); ui->diceChart = new QChartView(chart); ui->diceChart->repaint(); }
This code causes the QChartView to display nothing. However, I have tried things such as deleting the current chart given certain conditions, or setting the chartView's chart to a different chart, but those cause the program to crash after one or two operations. Why might this happen, and how do I correctly change the graph?
-
I am trying to change the displayed chart in a QChartView, but each time the program fails in some form.
void MainWindow::updateRollResult(QString rollResult, QChart* chart){ ui->rollResultLabel->setText("Sum of all dice rolls: " + rollResult); ui->diceChart = new QChartView(chart); ui->diceChart->repaint(); }
This code causes the QChartView to display nothing. However, I have tried things such as deleting the current chart given certain conditions, or setting the chartView's chart to a different chart, but those cause the program to crash after one or two operations. Why might this happen, and how do I correctly change the graph?
wrote on 22 Apr 2022, 06:05 last edited by@BradDev20 said in Properly changing the displayed chart in a QChartView:
ui->diceChart = new QChartView(chart);
Are you sure you do it here?
-
@BradDev20 said in Properly changing the displayed chart in a QChartView:
ui->diceChart = new QChartView(chart);
Are you sure you do it here?
wrote on 22 Apr 2022, 16:25 last edited by@A-A-SEZEN I have tried, but for some reason I just get a blank chart, even though I can confirm that the chart is being properly created.
-
Hi,
Why not use QChartView::setChart ?
What you currently do is just replacing the object pointed by
ui->diceView
by a different one, but that is all.
2/4