Unsolved Flickering with QChartView display
-
I am running a code on group of images and i have a function "updateGraph" used to plot a line graph to observe the number of cars encountered. I am calling this function for every image to update the graph, but i observe the flickering when graph is updated. I feel it is because i am creating a new widget every time i update the graph. Is there any way update the graph is same widget.?
void MainWindow::updateGraph() { QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(series); chart->createDefaultAxes(); chart->setTitle("Counts"); QChartView *chartview = new QChartView(chart); chartview->setRenderHint(QPainter::Antialiasing); gridLayout->addWidget(chartview,0,0); }
-
@rahult said in Flickering with QChartView display:
feel it is because i am creating a new widget every time i update the graph.
Correct, and even more - you forgot to delete the old ones and create a big memory leak.
You only have to update your series container, the rest is done automatically.
-
@Christian-Ehrlicher Thank you
How to delete the old ones.
Just by updating the series how can i update my graph. Where to call my updateGraph(). -
@rahult said in Flickering with QChartView display:
How to delete the old ones.
You mean old points? See e.g. https://doc.qt.io/qt-5/qxyseries.html#removePoints
-
@Christian-Ehrlicher Thank you..
As you saidYou only have to update your series container, the rest is done automatically.
i have declared the following in my mainwindow constructor
QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(series); chart->createDefaultAxes(); chart->setTitle("Counts"); QChartView *chartview = new QChartView(chart); chartview->setRenderHint(QPainter::Antialiasing); gridLayout->addWidget(chartview,0,0);
But when i am trying to access to chart from my other function it is not in scope. Did i get it correctly can you tell me whats going wrong.
-
Looks like basic c++ stuff is missing here...
You can for example make the chart or seriesa member variable. -
@Christian-Ehrlicher thank you.. solved the above issue declaring in constructor.
Series is getting updated but the chart is not getting updated.
-
@Christian-Ehrlicher I can able to solve the issue by adding chart->removeSeries(series); before updating the series. It works now.
But when i update the axes with chart->createDefaultAxes(); after chart->removeSeries(series); i see a blury chart likethis..
is there any other way to update the axes with updating the series.
-
There is no need to reset the series afaics. QChart::update() should suffice. If not please provide a testcase.