Retaining drawing across paintevents

A

angedward3

Hi all,

I am sub-classing the paintevent at the moment to create a 2D plot.

I find that I have to re-paint the whole widget every time I call an update(), as I have create a new QPainter() instance. Is there a way to update only a small part of the widget, while retaining the rest of the widget?

Thanks in advance
Ed

BTW if this is the wrong forum to post this, pls let me know.
 
C

Chris Angelico

I find that I have to re-paint the whole widget every time I call an update(), as I have create a new QPainter() instance. Is there a way to update only a small part of the widget, while retaining the rest of the widget?

In general, it would help to say which windowing toolkit you're using
:) Fortunately you mention something that implies you're using QT, so
I'm going to forge ahead with that.

When you call update(), you're effectively saying "the whole object
needs to be repainted". If you can restrict that to just a particular
rectangle, simply pass those coordinates to the update call:

http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#update-4

I'm not sure if you're using PyQt4 or not, but if you're using
something else, look through its docs for a similar function. Same
goes for pretty much any windowing toolkit; it's always possible to
report that a small area needs updating.

Once you then get the update event, you should be given a rectangle
that tells you which part needs to be repainted. But painting outside
that area will be reasonably fast, so don't stress too much about that
part if it's a lot of trouble. For instance, I have a MUD client that
will always attempt to draw complete lines, even if only part of a
line needs to be redrawn - but it'll repaint only those lines which
need repainting (so it looks at the Y coordinates of the "please
repaint me" rectangle, but not the X coords).

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top