2011-06-02 46 views
2

我試圖呈現一個QWebElement到QWidget的,但我的應用程序崩潰,但是如果我渲染成一個QImage的一切都很正常。渲染QWebElement成一個QWidget崩潰我的應用程序

這裏是我的代碼:

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

我使用Qt 4.7.3在Win 7(64位)。讓我知道我該如何解決這個問題。

+0

在'QImage'示例中'm_image'是爲了'ImageWidget'的成員? – Troubadour 2011-06-02 18:55:26

回答

0

我不會推薦在繪畫事件上渲染webelemnt。 Paint事件可以被觸發以經常使用,或者需要在Widget上只繪製微小的矩形。

更好的是有圖像緩衝並更新網頁元素更改。至少你可以嘗試寫「render(painter,paintEvent-> rect());」