How to repaint a QChart

后端 未结 2 863
离开以前
离开以前 2021-02-10 01:46

I\'d like to know how to repaint a QChart after I append new points to the QLineSeries added to it. The goal is to use this for displa

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-10 02:24

    First, if your will receive and append points at 400000 pts/sec in GUI thread, your application will get absolutely freezed. So you need to dedicate another thread to data receiving and processing, and send processed graphics data to the GUI thread using (for example) signals/slots connected with QueuedConnection. By "processing" I mean at least some sort of decimation (averaging, dropping, decimation as those DSP guys understand it), because 400000 pts/sec seems to fast, you'll waste your memory and GUI performance. But if you do not want to decimate, it's up to you. In this case you may consider a more lightweight data delivery mechanism than QueuedConnectioned signals/slots.

    The second question is when to plot? Not so long ago I implemented similar functionality with QCustomPlot at much lower rates. The main problem I faced was a huge (and varying) lag when I tried to replot after receiving each point, especially while plotting antialiased graph. In your case the solution is to subclass QChartView (I suppose you have already done it), override timerEvent in it and call startTimer()/killTimer() when you need to start/stop replotting. Alternatively, you may hold a timer in an object which owns the QChartView object and issue replotting from there, but it looks like abstraction leakage in comparison to subclassing QChartView. All in all, this approach allows you to achieve almost constant framerate and make it as smooth as you want without freezing application's interface.

    And finally, how to replot? QChartView seems to have repaint() method inherited from QWidget which does what you need.

提交回复
热议问题