June 2, 2011

pufuzbufu pufuzbufu
Lab Rat
2 posts

QPainter::begin: Paint device returned engine == 0, type: 1

 

Hi everyone. I have a simple QPainter program and I received this error when I’m trying to paint a widget.

here is the code:

  1. void MyGraphicsView::paintEvent(QPaintEvent *event)
  2. {
  3.     QPainter p(this);
  4.     p.setPen(Qt::red);
  5.     p.drawText(10,10,"some text");
  6.  
  7. }

here you can download a small sample project in case you wanna test it yourself: http://www.box.net/shared/yitvqvfcdv

6 replies

June 2, 2011

peppe peppe
Ant Farmer
1028 posts

Didn’t download the snippet, but if that class is a subclass of a QGraphicsView (and in general of a QAbstractScrollArea), you need to paint on the viewport().

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

June 2, 2011

sriks sriks
Lab Rat
122 posts

Try paint on the graphicsview’v viewport. GraphicsView will always paint its content to its viewport.

June 2, 2011

pufuzbufu pufuzbufu
Lab Rat
2 posts

ok. thanks. that worked. However now I’m facing a similar problem:

I’m trying to render a QWebElement into a QWidget and I received the same error. here is my code:

  1. QPainter painter(this->imageWidget);
  2. this->webElement.render(&painter);

I receive the following errors:

QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setBrush: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::save: Painter not active
QPainter::translate: Painter not active
QPainter::save: Painter not active

August 26, 2014

astodolski astodolski
Ant Farmer
220 posts

pufuzbufu wrote:
Hi everyone. I have a simple QPainter program and I received this error when I’m trying to paint a widget.

here is the code:

  1. void MyGraphicsView::paintEvent(QPaintEvent *event)
  2. {
  3.     QPainter p(this);
  4.     p.setPen(Qt::red);
  5.     p.drawText(10,10,"some text");
  6.  
  7. }

here you can download a small sample project in case you wanna test it yourself: http://www.box.net/shared/yitvqvfcdv

Downloaded, compiled, run. Draws nothing!

August 26, 2014

SGaist SGaist
Mad Scientist
10045 posts

Hi,

Why are you reviving a post that’s more than 3 years old ?

 Signature 

Need programers to hire ? www.edeltech.ch

August 26, 2014

astodolski astodolski
Ant Farmer
220 posts

SGaist wrote:
Hi,

Why are you reviving a post that’s more than 3 years old ?

It’s in the context of a problem I searched. Still the sample linked doesn’t work. Change the forum engine so it can’t be commented on (reviving) if that’s causing a problem.

 
  ‹‹ Difference in release and debug versions      Parsing Text from File ››

You must log in to post a reply. Not a member yet? Register here!