[Qt-interest] Paint QWebView to a QImage

Girish Ramakrishnan girish at forwardbias.in
Thu Dec 17 05:42:48 CET 2009


Hi,
Use a plain QWebPage and connect to it' repaintRequested(QRect). You can
then pass that QRect to QWebFrame's render() to update only the portion
that got changed.

(Also, your approach on changing the paintEngine won't work. Just
reimplementing QWidget::paintEngine() doesn't actually switch the paint
engine - It's complicated)

Girish

Richard Hosking wrote:
> Hello, I am trying to render the contents of a QWebView
> to a QImage instance.
> 
> I have tried the QWebFrame->render(QImage) method, but this
> is not the correct approach for me as I need to render
> at several frames a second.  I really only want to render
> when changes occur on the widget to keep CPU usage down.
> 
> What I would ideally like is for QWebView to render directly
> to a QImage.
> 
> I have tried subclassing QWebView's paintEngine() and
> returning my QImage->paintEngine() but the image remains
> unchanged.
> 
> I have also tried hooking into QWebView's event() and
> listening for QEvent::Paint then calling
> QPainter::setRedirected(QWebView, QImage) but again nothing
> is produced in the image.
> 
> Any pointers?
> 
> (Qt 4.5.1 on Linux)
> 
> Kind regards,
> Richard.



More information about the Qt-interest-old mailing list