0

如您所见,我的代码非常简单,它只定期调用 QLineSeries.replace(QPolygonF) 。

但是当代码执行时,应用程序使用的内存不断增加。

import sys

from PyQt5.QtCore import QTimer
from PyQt5.QtGui  import QPolygonF
from PyQt5.QtWidgets import QApplication, QMainWindow

from PyQt5.QtChart import QChart, QChartView, QLineSeries

class DemoWindow(QMainWindow):
    def __init__(self, parent=None):
        super(DemoWindow, self).__init__(parent=parent)

        self.plotChart = QChart()
        self.plotChart.legend().hide()

        self.plotView = QChartView(self.plotChart)
        self.setCentralWidget(self.plotView)

        self.plotCurve = QLineSeries()
        self.plotChart.addSeries(self.plotCurve)

        self.plotChart.createDefaultAxes()

        self.polyline = QPolygonF(1000)

        self.tmrPlot = QTimer()
        self.tmrPlot.setInterval(100)
        self.tmrPlot.timeout.connect(self.on_tmrPlot_timeout)
        self.tmrPlot.start()

    def on_tmrPlot_timeout(self):
        self.plotCurve.replace(self.polyline)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = DemoWindow()
    win.show()
    sys.exit(app.exec_())
4

0 回答 0