Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62962 > unrolled thread

Retaining drawing across paintevents

Started byangedward3@gmail.com
First post2014-01-01 06:53 -0800
Last post2014-01-02 02:05 +1100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Retaining drawing across paintevents angedward3@gmail.com - 2014-01-01 06:53 -0800
    Re: Retaining drawing across paintevents Chris Angelico <rosuav@gmail.com> - 2014-01-02 02:05 +1100

#62962 — Retaining drawing across paintevents

Fromangedward3@gmail.com
Date2014-01-01 06:53 -0800
SubjectRetaining drawing across paintevents
Message-ID<396bc9f8-2ed6-4ebf-853d-a50e3c7ce521@googlegroups.com>
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.

[toc] | [next] | [standalone]


#62964

FromChris Angelico <rosuav@gmail.com>
Date2014-01-02 02:05 +1100
Message-ID<mailman.4782.1388588765.18130.python-list@python.org>
In reply to#62962
On Thu, Jan 2, 2014 at 1:53 AM,  <angedward3@gmail.com> wrote:
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web