PDA

View Full Version : Update a QGraphicsScene every x seconds automatically



Nezgal
26th May 2013, 01:48
Hello.

Here is what I want to do:
I have a QGraphicsScene containing a grid. I have a function updateGrid. I have a button step that updates manually the grid.
I want to make a button play that automatically updates the grid every n seconds.
I tried using Python sched but it seems to work fine to print in the console every n seconds, but when I set it up to update the grid, the whole application freezes and I must force it to quit.

Here is the code:


def play(self) :
self.play = True
s = sched.scheduler(time.time, time.sleep)
s.enter(1, 1, self.playRec, (s,))
s.run()


def playRec(self, sc) :
if self.play :
self.updateGrid()
print "blah"
sc.enter(5, 1, self.playRec, (sc,))

How can I do this?

Thank you very much!

Nezgal
26th May 2013, 04:37
Nevermind, I found how to do it, using a QTimer :)

wysota
26th May 2013, 07:55
Connect the timer's timeout() signal to advance() slot in the scene.