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

Qt-interest Archive, January 2007
QPainter Error


Message 1 in thread

I am getting the following error message;
"QPainter::begin(): Widget painting can only begin as a result of a 
paintEvent". This happens when I instatiate a QPainter thus:
   QPainter painter(&m_Pixmap);
   painter.initFrom(this);

   // erasePlot added 3 July 2005
   erasePlot(&painter);

Is this really an illegal operation? It did not happen in Qt3. I am 
using Qt4.2.1, MS Visual C++.net 2003, converting a large project from Qt3.

--
 [ signature omitted ] 

Message 2 in thread

Am Montag, 1. Januar 2007 18:03 schrieb Kenneth Beck:
> I am getting the following error message;
> "QPainter::begin(): Widget painting can only begin as a result of a
> paintEvent". This happens when I instatiate a QPainter thus:
>    QPainter painter(&m_Pixmap);
>    painter.initFrom(this);
>
>    // erasePlot added 3 July 2005
>    erasePlot(&painter);
you probably called these instructions from within another method than a 
reimplementation of paintEvent(...). In Qt4 you can only use QPainters inside 
paintEvent(...)

toby

Attachment:

Attachment: pgpewyQTrXE78.pgp
Description: PGP signature


Message 3 in thread

On Monday 01 January 2007 18:30, Tobias Doerffel wrote:
> Am Montag, 1. Januar 2007 18:03 schrieb Kenneth Beck:
> > I am getting the following error message;
> > "QPainter::begin(): Widget painting can only begin as a result of a
> > paintEvent". This happens when I instatiate a QPainter thus:
> >    QPainter painter(&m_Pixmap);
> >    painter.initFrom(this);
> >
> >    // erasePlot added 3 July 2005
> >    erasePlot(&painter);
>
> you probably called these instructions from within another method than a
> reimplementation of paintEvent(...). In Qt4 you can only use QPainters
> inside paintEvent(...)

It should be noted that this isn't entirely correct. You can perfectly well 
use QPainters on images and pixmaps at any time. QPainters on /widgets/ 
however can indeed only be used from within paintEvent().

From the above code snippet it seems the painter is initialized on a pixmap 
though. I suspect that somewhere else in the program a painter is initialized 
on a widget outside of paintEvent().

Simon

Attachment:

Attachment: pgpXUlQ8PeyKr.pgp
Description: PGP signature


Message 4 in thread

Simon Hausmann wrote:
> On Monday 01 January 2007 18:30, Tobias Doerffel wrote:
>> Am Montag, 1. Januar 2007 18:03 schrieb Kenneth Beck:
>>> I am getting the following error message;
>>> "QPainter::begin(): Widget painting can only begin as a result of a
>>> paintEvent". This happens when I instatiate a QPainter thus:
>>>    QPainter painter(&m_Pixmap);
>>>    painter.initFrom(this);
>>>
>>>    // erasePlot added 3 July 2005
>>>    erasePlot(&painter);
>> you probably called these instructions from within another method than a
>> reimplementation of paintEvent(...). In Qt4 you can only use QPainters
>> inside paintEvent(...)
> 
> It should be noted that this isn't entirely correct. You can perfectly well 
> use QPainters on images and pixmaps at any time. QPainters on /widgets/ 
> however can indeed only be used from within paintEvent().
> 
> From the above code snippet it seems the painter is initialized on a pixmap 
> though. I suspect that somewhere else in the program a painter is initialized 
> on a widget outside of paintEvent().
> 
> Simon
OK, turns out Simon is correct -- I was calling bitBlt on a Widget, when 
  I caught that, the error message went away.

--
 [ signature omitted ]