March 16, 2012

Vetryaspa Vetryaspa
Lab Rat
87 posts

QGraphicsView print error : “QPainter::begin: Paint device returned engine == 0, type: 1”

 

  1. class MappaRegioni : public QGraphicsView
  2.  
  3. { [...] }
  4.  
  5. bool MappaRegioni::viewportEvent(QEvent *event)
  6. {
  7.    
  8.     QPainter painter(this);
  9.     QImage *euro = new QImage(QSize(35,29),QImage::Format_ARGB32_Premultiplied);
  10.     QString euroName(":/new/Generale/Grafiche/Varie/IconAddress.png");
  11.     euro->load(euroName);
  12.     painter.drawImage(QPoint(150,150) ,*euro);
  13. }

Why return this error? I have read some post and i have found that the viewportEvent() method paint!!

What my error is?

Regards

2 replies

March 21, 2012

Vetryaspa Vetryaspa
Lab Rat
87 posts

No body can help me?

May 15, 2013

dhaumann dhaumann
Lab Rat
3 posts

In general, you should, and in fact mostly cannot paint outside paint events (if you really really need this, you have to enable painting outside of the paintEvent by setting the flag Qt::WA_PaintOutsidePaintEvent. This is highly discouraged, though!).

If you want to paint in the QGraphiscView, You should reimplement QGraphicsView::paintEvent().

However, the correct solution is to use one of the two dedicated functions in QGraphicsView that allow you to paint behind all items in the background, or as overlay on top of all items:
virtual void drawBackground ( QPainter * painter, const QRectF & rect )
virtual void drawForeground ( QPainter * painter, const QRectF & rect )

Please look in the Qt Assistant documentation in QGraphicsView for further details.

 
  ‹‹ Question about debug and release mode.      QNetworkAccessManager Failed to make connection with https server ››

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