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

Scott Aron Bloom Scott.Bloom at sabgroup.com
Tue Jun 2 18:39:04 CEST 2009


Have an image owned by the QUcsView object.

 

In resize make sure you are resizing the image

 

Everywhere you are currently calling QPainter (viewport()) paint onto
the image.

 

In your paint call, draw the image to the actual painter

 

Scott

 

 

 

From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of shivam
priyadarshi
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
inQT4.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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090602/9a610261/attachment.html 


More information about the Qt-interest-old mailing list