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



  • @
    class MappaRegioni : public QGraphicsView

    { [...] }

    bool MappaRegioni::viewportEvent(QEvent *event)
    {

    QPainter painter(this);
    QImage *euro = new QImage(QSize(35,29),QImage::Format_ARGB32_Premultiplied);
    QString euroName(":/new/Generale/Grafiche/Varie/IconAddress.png");
    euro->load(euroName);
    painter.drawImage(QPoint(150,150) ,*euro);
    

    }

    @

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

    What my error is?

    Regards



  • No body can help me?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.