开发者

Rendering a QWebElement into a QWidget crashes my application

I'm trying to render a QWebElement into a QWidget but my app crashes, however if I render it into an QImage everything works great.

Here is my code:

// using this code my application is crashing
void ImageWidget::paintEvent(QPaintEvent *)
{
    if (this->imgElement != NULL)
    {
        QPainter p(this);
        this->imgElement->render(&p);
        p.end();
    }
}

// using this one everything works OK
void ImageWidget::saveImage(QWebElement *el)
{
    this->imgEl开发者_如何学Cement = el;
    QImage m_image = QImage(290, 80, QImage::Format_ARGB32_Premultiplied);
    m_image.fill(Qt::transparent);
    QPainter p(&m_image);
    el->render(&p);
    p.end();
    m_image.save("some_file.png", "png");
    this->update();
}

I'm using Qt 4.7.3 on Win 7 (x64). Let me know how can I fix this.


I wouldn't recommend rendering webelemnt on paint event. Paint events can be fired to often or require to draw only tiny rect on widget.

Better to have image buffer and update it on web element change.

At least you can try to write "render ( painter, paintEvent->rect() );"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜