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

Qt-interest Archive, June 2007
QPainter::begin: Widget painting can only begin as a result of a paintEvent


Message 1 in thread

Hi, o wise ones :-)

I get the following error message with qt 4.2 and kdevelop 3.4.0

QPainter::begin: Widget painting can only begin as a result of a paintEvent

This is part of the code with the error:

    QImage *image;
    QFrame* imageFrame;

void qpixy::paintEvent( QPaintEvent * )
{
    QPainter imagePainter( imageFrame );
    imagePainter.drawImage( QPoint(0,0), *image); 
}

But when i do 
    QPainter imagePainter( this );
instead of 
    QPainter imagePainter( imageFrame );
Then it works fine.

I have looked in the porting from qt3 to qt4.
There is something about reimplementing paintEvent, but i do not know how.
And can not find via google a way which i understand.

How can i paint the qimage in the qframe ?

I humbly bow my head and say : Thank you :-)


--
 [ signature omitted ] 

Message 2 in thread

On 6/5/07, hihihi <hihihi@xxxxxxxxxx> wrote:
>
> Hi, o wise ones :-)
>
> I get the following error message with qt 4.2 and kdevelop 3.4.0
>
> QPainter::begin: Widget painting can only begin as a result of a paintEvent
>
> This is part of the code with the error:
>
>     QImage *image;
>     QFrame* imageFrame;
>
> void qpixy::paintEvent( QPaintEvent * )
> {
>     QPainter imagePainter( imageFrame );
>     imagePainter.drawImage( QPoint(0,0), *image);
> }
>
> But when i do
>     QPainter imagePainter( this );
> instead of
>     QPainter imagePainter( imageFrame );
> Then it works fine.
>
> I have looked in the porting from qt3 to qt4.
> There is something about reimplementing paintEvent, but i do not know how.
> And can not find via google a way which i understand.
>
> How can i paint the qimage in the qframe ?

You must paint a widget in its *own* paintEvent method, not *any*
widget's paintEvent method. Subclass the Qt widget on which you want
to paint and implement an appropriate paintEvent.
-- 
 [ signature omitted ]