Results 1 to 3 of 3

Thread: Update a QGraphicsScene every x seconds automatically

  1. #1
    Join Date
    May 2013
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Update a QGraphicsScene every x seconds automatically

    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:

    Qt Code:
    1. def play(self) :
    2. self.play = True
    3. s = sched.scheduler(time.time, time.sleep)
    4. s.enter(1, 1, self.playRec, (s,))
    5. s.run()
    6.  
    7.  
    8. def playRec(self, sc) :
    9. if self.play :
    10. self.updateGrid()
    11. print "blah"
    12. sc.enter(5, 1, self.playRec, (sc,))
    To copy to clipboard, switch view to plain text mode 

    How can I do this?

    Thank you very much!

  2. #2
    Join Date
    May 2013
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update a QGraphicsScene every x seconds automatically

    Nevermind, I found how to do it, using a QTimer

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update a QGraphicsScene every x seconds automatically

    Connect the timer's timeout() signal to advance() slot in the scene.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsScene::update() has no effect
    By pmwalk in forum Newbie
    Replies: 4
    Last Post: 24th February 2012, 16:10
  2. Replies: 0
    Last Post: 12th July 2011, 08:19
  3. Replies: 5
    Last Post: 30th January 2010, 10:09
  4. Can't manually update QGraphicsScene
    By aladagemre in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2010, 21:52
  5. QGraphicsScene update?
    By Gurdt in forum Qt Programming
    Replies: 11
    Last Post: 17th April 2009, 09:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.