[PyQt] PyQt-based Tetr*s

Joshua Bronson jabronson at gmail.com
Wed Mar 26 20:51:29 GMT 2008


On Wed, Mar 26, 2008 at 4:48 PM, Matt Newell <newellm at blur.com> wrote:

>
> >
> > Thanks Matt, that did the trick.
> >
> > Another question has come up. When implementing this in less
> sophisticated
> > Gui
> > frameworks<http://aipytris.googlecode.com/svn/trunk/aipytris/boardtk.py>,
> I
> > noticed that the canvas remembered primitives that had already been
> painted
> > on it, so on each paint event I only had to paint blocks that had moved
> > since the previous paint event, which I assume is more efficient. With
> my
> > Qt version, however, I am repainting every block on every paint event,
> even
> > ones that have not moved. Is there some way around this? I've looked at
> the
> > painting examples and read http://doc.trolltech.com/4.3/paintsystem.html
> ,
> > but I haven't found anything about whether QWidgets can retain state.
> >
> > Thanks,
> > Josh
>
>
> When you call QWidget::update, it considers the entire widget to be
> "dirty".
> By default is clears the dirty portion with the background color role.
>  You
> can disable the clearing by calling QWidget::setAttribute with
> Qt::WA_OpaquePaintEvent or Qt::WA_NoSystemBackground(i'll leave it to you
> to
> decide which).  Then you can keep track yourself what needs to be drawn.
>
> You can also limit the dirty region by calling update( QRect ) for each
> dirty
> rect.  You can call update multiple times and it will only result in a
> single
> paint event, with all the rects joined into a QRegion.
>
> Matt
>

Thanks again Matt for the lightning-fast reply. That sounds like just the
info I need. I did a quick search for "NoSystemBackground" and found
http://doc.trolltech.com/qq/qq16-background.html. Is there any other
documentation you know of that you would recommend?

A bigger question is whether you think it's worth it. Things are working
just fine the way they are now, and at most each of my BoardQt instances is
only ever going to have to paint less than 20x9 = 180 QRects per paintEvent.
Am I likely to hit scaling problems any time soon if I have a multiplayer
game with several BoardQt instances painting at once? Is it worth doing it
the efficient way just on principle?

Thanks!

Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080326/86170c41/attachment.html


More information about the PyQt mailing list