是否有任何选项可以在不冻结界面的情况下每秒执行paintEvent
一次该功能?30
from typing import Sized
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QRadialGradient, QPainter, QPainterPath, QPen, QBrush, QGradient, QColor
from PyQt5.QtCore import QPointF, Qt, QRect
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.centralwidget = QtWidgets.QWidget()
self.setCentralWidget(self.centralwidget)
self.resize(600, 400)
def paintEvent(self, event):
self.painter = QPainter(self)
radialGrad = QRadialGradient(QPointF(300, 450), 200)
radialGrad.setColorAt(0, QColor('#1B2735'))
radialGrad.setColorAt(1, QColor('#090A0F'))
self.painter.setBrush(radialGrad)
self.painter.drawRect(0, 0, 600, 400)
self.painter.setBrush(QBrush(Qt.white))
self.painter.drawRect(100, 390, 2, 2)
self.painter.drawRect(200, 390, 3, 3)
self.painter.drawRect(300, 390, 4, 4)
self.update()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
该类
QTimer
提供循环和一次性计时器。更多https://doc.qt.io/qt-5/qtimer.html