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:
    @void MyGraphicsView::paintEvent(QPaintEvent *event)
    {
    QPainter p(this);
    p.setPen(Qt::red);
    p.drawText(10,10,"some text");

    }@

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



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



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



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

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

    I receive the following errors:

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



  • [quote author="pufuzbufu" date="1307012108"]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:
    @void MyGraphicsView::paintEvent(QPaintEvent *event)
    {
    QPainter p(this);
    p.setPen(Qt::red);
    p.drawText(10,10,"some text");

    }@

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

    Downloaded, compiled, run. Draws nothing!


  • Lifetime Qt Champion

    Hi,

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



  • [quote author="SGaist" date="1409084983"]Hi,

    Why are you reviving a post that's more than 3 years old ?[/quote]

    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.


Log in to reply
 

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