[Qt-interest] Getting QGraphicsView drawItems to yield/restartbefore completion?

Ross Bencina rossb-lists at audiomulch.com
Wed Sep 30 04:55:35 CEST 2009


Hi Scott

I havn't implemented pre-emptive re-rendering myself, but I imagine you could render tiles to offscreen pixmaps and then display these (perhaps QGraphicsView has some kind of tile-cached mode for this these days(?). Because you're rendering tiles rather than the whole scene, this would give you some granularity for preempting the render and starting again (and reusing previous results). Google for "tile scrolling" gives a few results.

You could implement this with two Graphics Scenes: one for the tiles and one for the real scene. Use a 0 duration timer to invalidate one tile at a time.. that way mouse events will get processed before/after each tile is rendered and you wouldn't need to use a separate thread.

Another thing is, I'm not sure how you're currently processing (mouse/keyboard) input for pan and zoom but one thing is to make sure you've processed all input events before initiating another redraw cycle so that the redraw is only ever lagging one redraw cycle behind the mouse. I think Qt will guarantee all mouse/keyboard events are dispatched before paint events, but I'm not 100% sure about this...

Just my 2 cents

Ross.


----- Original Message ----- 
  From: Scott Stafford 
  To: qt-interest at trolltech.com 
  Sent: Wednesday, September 30, 2009 4:51 AM
  Subject: [Qt-interest] Getting QGraphicsView drawItems to yield/restartbefore completion?


  I'm trying to draw a large and complex QGraphicsScene and once I add a lot of objects, panning and zooming become unpleasantly slow.  (No surprise here, of course).  I've played with device coordinate caching (helps with panning to a point) and minimal viewport updates and so on, but eventually there's just too many objects.  What I'd like to do is draw the items asynchronously from controlling the UI somehow.  In other words, just like Google Maps does, I want to pan and zoom and let drawing catch up as fast as it's able, but to be able to pan again before the items finish drawing.

  Is this possible?  I was thinking it would take a rewritten QGraphicsScene::drawItems function that signals another thread to loop through the items until told to start over.  Has anyone tried anything like this?

  Scott



------------------------------------------------------------------------------


  _______________________________________________
  Qt-interest mailing list
  Qt-interest at trolltech.com
  http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090930/e0b25f30/attachment.html 


More information about the Qt-interest-old mailing list