2

我正在尝试将 QWebElement 渲染到 QWidget 中,但是我的应用程序崩溃了,但是如果我将它渲染到 QImage 中,一切都很好。

这是我的代码:

// 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->imgElement = 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();
}

我在 Win 7 (x64) 上使用 Qt 4.7.3。让我知道我该如何解决这个问题。

4

1 回答 1

0

我不建议在绘画事件上渲染 webelemnt。绘制事件可以经常触发或只需要在小部件上绘制微小的矩形。

最好有图像缓冲区并在 Web 元素更改时对其进行更新。

至少你可以尝试写“render (painter,paintEvent->rect());”

于 2012-02-24T14:14:33.890 回答