Retaining drawing across paintevents

Discussion in 'Python' started by angedward3@gmail.com, Jan 1, 2014.

  1. Guest

    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.
     
    , Jan 1, 2014
    #1
    1. Advertising

  2. On Thu, Jan 2, 2014 at 1:53 AM, <> 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
     
    Chris Angelico, Jan 1, 2014
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ALuPin

    Retaining not used nodes

    ALuPin, Feb 8, 2005, in forum: VHDL
    Replies:
    2
    Views:
    468
    Christos
    Feb 8, 2005
  2. Earl Teigrob
    Replies:
    0
    Views:
    411
    Earl Teigrob
    Aug 11, 2003
  3. Replies:
    1
    Views:
    676
    Kevin Spencer
    Jan 9, 2006
  4. defn noob
    Replies:
    1
    Views:
    420
    Mark Space
    Jun 28, 2008
  5. Karthikeyan
    Replies:
    1
    Views:
    341
Loading...

Share This Page