【问题标题】:Rendering a QWebElement into a QWidget crashes my application将 QWebElement 渲染到 QWidget 会使我的应用程序崩溃
【发布时间】:2012-02-24 22:14:33
【问题描述】:

我正在尝试将 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。让我知道如何解决这个问题。

【问题讨论】:

  • QImage 示例中,m_imageImageWidget 的成员?

标签: qt qt4 qtwebkit


【解决方案1】:

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

最好有图像缓冲区并在 web 元素更改时更新它。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多