Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, December 2006
Can we get notified of a QPaintEvent before QWidget::paintEvent() is called ?


Message 1 in thread

Hi all,

The Qt 422 doc for QPixmap::grabWidget() says :
        > Warning: Do not call this function from QWidget::paintEvent().

Unfortunately, I really need to use grabWidget "from within", or, better,
just-before paintEvent() is executed.

So... Is there a way to get notified that a QPaintEvent is about to be
delivered BEFORE QWidget::paintEvent() is called ?

I've thought of subclassing QWidget::event().

As far as I understand, QWidget::event() should be called prior to any other
event handler, and does the actual calls to the "specialized" event
handler. But... I do not succeed with my trials...


Any other idea ?



DETAILS :

In a GLwidget, I'd need to update some stuff before the drawGL() method is
called.
Especially, I'd need to update some QPixmap by using QPixmap::grabWidget().

I'd like to make it "just before" drawGl(), because that way I can benefit
from the accumulation made by Qt of the calls to update() before the actual
painting is triggered.

But... 

Then, I need to "update my stuff" BEFORE drawGl and paintEvent are actually
called...

Thanks in advance,
Best-
Nicolas




--
 [ signature omitted ] 

Message 2 in thread

You cannot grab the widget that's getting painted - because all that 
QPixmap::grabWidget does is send a paint event to the widget you are 
grabbing, after redirecting the painter.

You can grab other widgets.

The earliest you get into the stack trace before paintEvent() is called is 
QWidget::event() for QEvent::Paint.


Volker


"Nicolas Castagne" <castagne@xxxxxxx> wrote in message 
news:eluhas$4ek$1@xxxxxxxxxxxxxxxxxxxxx
> Hi all,
>
> The Qt 422 doc for QPixmap::grabWidget() says :
>        > Warning: Do not call this function from QWidget::paintEvent().
>
> Unfortunately, I really need to use grabWidget "from within", or, 
> better,
> just-before paintEvent() is executed.
>
> So... Is there a way to get notified that a QPaintEvent is about to be
> delivered BEFORE QWidget::paintEvent() is called ?
>
> I've thought of subclassing QWidget::event().
>
> As far as I understand, QWidget::event() should be called prior to any 
> other
> event handler, and does the actual calls to the "specialized" event
> handler. But... I do not succeed with my trials...
>
>
> Any other idea ?
>
>
>
> DETAILS :
>
> In a GLwidget, I'd need to update some stuff before the drawGL() method 
> is
> called.
> Especially, I'd need to update some QPixmap by using 
> QPixmap::grabWidget().
>
> I'd like to make it "just before" drawGl(), because that way I can 
> benefit
> from the accumulation made by Qt of the calls to update() before the 
> actual
> painting is triggered.
>
> But...
>
> Then, I need to "update my stuff" BEFORE drawGl and paintEvent are 
> actually
> called...
>
> Thanks in advance,
> Best-
> Nicolas
>
>
>
> 


--
 [ signature omitted ] 

Message 3 in thread

Hi,

maybe you can work around by setting a bool variable before grabWidget() 
and do this grabWidget only if the bool flag is false.
Like this (not tested):

bool isGrabbing = false;

void paintEvent( QEvent* )
{
  if( !isGrabbing ) {
    isGrabbing = true;
    QPixmap map = QPixmap::grabWidget( this );
    isGrabbing = false;
  }
  doYourPaintStuff();
}

Hope that helps, good luck
Daniel


Volker Hilsheimer schrieb:
> You cannot grab the widget that's getting painted - because all that 
> QPixmap::grabWidget does is send a paint event to the widget you are 
> grabbing, after redirecting the painter.
>
> You can grab other widgets.
>
> The earliest you get into the stack trace before paintEvent() is called is 
> QWidget::event() for QEvent::Paint.
>
>
> Volker
>
>
> "Nicolas Castagne" <castagne@xxxxxxx> wrote in message 
> news:eluhas$4ek$1@xxxxxxxxxxxxxxxxxxxxx
>   
>> Hi all,
>>
>> The Qt 422 doc for QPixmap::grabWidget() says :
>>        > Warning: Do not call this function from QWidget::paintEvent().
>>
>> Unfortunately, I really need to use grabWidget "from within", or, 
>> better,
>> just-before paintEvent() is executed.
>>
>> So... Is there a way to get notified that a QPaintEvent is about to be
>> delivered BEFORE QWidget::paintEvent() is called ?
>>
>> I've thought of subclassing QWidget::event().
>>
>> As far as I understand, QWidget::event() should be called prior to any 
>> other
>> event handler, and does the actual calls to the "specialized" event
>> handler. But... I do not succeed with my trials...
>>
>>
>> Any other idea ?
>>
>>
>>
>> DETAILS :
>>
>> In a GLwidget, I'd need to update some stuff before the drawGL() method 
>> is
>> called.
>> Especially, I'd need to update some QPixmap by using 
>> QPixmap::grabWidget().
>>
>> I'd like to make it "just before" drawGl(), because that way I can 
>> benefit
>> from the accumulation made by Qt of the calls to update() before the 
>> actual
>> painting is triggered.
>>
>> But...
>>
>> Then, I need to "update my stuff" BEFORE drawGl and paintEvent are 
>> actually
>> called...
>>
>> Thanks in advance,
>> Best-
>> Nicolas
>>
>>
>>
>>
>>     
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   


-- 
 [ signature omitted ]