Pyqt图QLineSeries.replace(QPolygonF)生成内存

2024-09-22 16:39:37 发布

您现在位置:Python中文网/ 问答频道 /正文

如您所见,我的代码非常简单,它只调用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_())

Tags: fromimportselfsystimeoutreplacepyqt5parent