Question

I am using a QWidget to render x and y-repeated shapes in different color progressions and like to transform these colors over time. In this widget I rely on QPainter's drawing api solely to draw and create the shapes.

What is the best way to put a particular widget into an animation loop with Qt4, so that paintEvent() is fired periodically, preferably at a configurable frame rate / time interval? (much like what tools like processing do with their stage)

Additionally, would you recommend using another widget type for this kind of task?

Était-ce utile?

La solution

Users over at reddit got me on the right track: http://redd.it/24kogy

As suggested there QTimer works fine. In the class of your widget you could apply it like this:

timer = QTimer(self)
timer.setInterval(20) # interval in ms
self.connect(timer, SIGNAL("timeout()"), self.update)
timer.start()

Relevant imports are

from PySide.QtCore import QTimer, SIGNAL
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top