paintEvent调用
其实就是想每隔一段时间就更新一下颜色,想到了用time.sleep(2)可是,真正在用的时候发现代码只进入paintEvent一次,不知道该如何多次调用paintEvent
import sys
import time
from PyQt4 import QtGui
from PyQt4 import QtCore
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle( "Test" )
self.setGeometry(500, 500, 300, 300)
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self)
self.drawRect(qp)
qp.end()
def drawRect(self, qp):
qp.setBrush(QtGui.QColor(0, 0, 0, 255))
qp.drawRect(50, 50, 50, 50)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
hi = Example()
hi.show()
app.exec_()
你调用widget的update进行更新
[解决办法]
paintEvent什么时候被调用