폴리 라인을 애니메이션으로 만들려고합니다 (웨이브처럼 행동해야합니다). 이 방법을 시도했습니다 :PySide/PyQt에서 drawPolyline을 사용하여 애니메이션 웨이브 만들기
from PySide.QtCore import *
from PySide.QtGui import *
import sys, time
class Test(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
def poly(self, pts):
return QPolygonF(map(lambda p: QPointF(*p), pts))
def paintEvent(self, event):
painter = QPainter(self)
pts = [[80, 490], [180, 0], [280, 0], [430, 0], [580, 0], [680, 0], [780, 0]]
for i in pts:
while i[1] < 600:
painter.setPen(QPen(QColor(Qt.darkGreen), 3))
painter.drawPolyline(self.poly(pts))
painter.setBrush(QBrush(QColor(255, 0, 0)))
painter.setPen(QPen(QColor(Qt.black), 1))
for x, y in pts:
painter.drawEllipse(QRectF(x - 4, y - 4, 8, 8))
i[1] += 1
print pts
time.sleep(0.0025)
self.update()
if __name__ == '__main__':
example = QApplication(sys.argv)
test2 = Test()
test2.resize(800, 600)
test2.show()
sys.exit(example.exec_())
하지만 작동하지 않습니다! 프로그램이 실행될 때 화면에 혼란이 있습니다. 그것은 self.update()
창이 업데이트되지 않는 것 같습니다. 도와주세요.