[Qt-interest] [Qt-Interest] Painting outside paintEvent in QT4.5 : Widget painting can only begin as a result of a paintEvent

Malyushytsky, Alex alex at wai.com
Wed Jun 3 02:29:38 CEST 2009


Shivam,

>> So if i follow approach  A does this mean  i should open  the painter on Qpixmap  or  Qimage rather than on viewport.

Yes, 
And make sure that pixmap has correct size  (size of viewport?) which is updated when widget size is changed.
I would probably suggest having two pixmaps to simplify synchronization.

One stores what is currently displayed in the widget. 
Another the one you plot in.

1. Once plotting done the first pixmap is replaced and update is called.

2. If widget is resized just call function which start painting.
(Or if painting is a long operation, you may scale current pixmap and post a custom event, and implement event handler which will start painting)

You drawing function should check if size of pixmap is the same as viewport, do proper initialization if required and plot in the pixmap.

Hope this helps.

Regards,
   Alex
   

From: shivam priyadarshi [mailto:shivam.priyadarshi at gmail.com] 
Sent: Tuesday, June 02, 2009 7:45 AM
To: Malyushytsky, Alex
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest] [Qt-Interest] Painting outside paintEvent in QT4.5 : Widget painting can only begin as a result of a paintEvent

Hi Alex and Thiago,

Thank you very much for replying back.  Actually in my GUI code i am painting on Scroll Area (QAbstractScrollArea in Qt4.5 and Q3ScrollView in support function).  So as paintEvent function of QAbstractScrollArea says, always open a painter on the viewport(). So Painter is always opened on viewport(). 

So if i follow approach  A does this mean  i should open  the painter on Qpixmap  or  Qimage rather than on viewport.

I am doing like following which worked fine with 3.3

void QucsView::MMovePainting(QMouseEvent *Event)
{
Qpainter painter(viewport());
setPainter(&painter);
update();
}

where setPainter is function where painting is done and QucsView class inherit Q3ScrollView.

Regards:
Shivam



On Mon, Jun 1, 2009 at 10:20 PM, Malyushytsky, Alex <alex at wai.com> wrote:
According to how I see it:

Approach A (simplest)
------------------------------------------------------------------
Instead of painting to the widget, paint to the QPixmap or QImage.
Update the widget when painting done.

+ minimum changes to the paining code.
- sometimes update of the whole widget from image is inefficient and it might be not that easy to implement it efficiently.
  And things got worse when you like to see evolution of the drawing on the screen instead of the result.


Approach B (never tried, but it looks promising, if I don't make any mistake about it functionality)
------------------------------------------------------------------
Paint to QPicture, store QPicture object(s).
Call update when required, use QPicture object to draw in the paint event.

I can't recommend it, cause I never tried, but it seems more powerful.


Best regards,

Alex




-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Thiago Macieira
Sent: Saturday, May 30, 2009 2:52 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] [Qt-Interest] Painting outside paintEvent in QT4.5 : Widget painting can only begin as a result of a paintEvent

shivam priyadarshi wrote:
>I have this kind of code structure at various places in application. I
>have tight schedule, it will be great help if you can help me with make
>it work with QT4.5 with painting outside paintEvent.

You have to refactor your code so that you paint only inside the paintEvent.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
 Senior Product Manager - Nokia, Qt Software
     Sandakerveien 116, NO-0402 Oslo, Norway

---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list