[Qt-interest] Paint QWebView to a QImage
Richard Hosking
richard at hovis.net
Fri Jan 1 17:15:51 CET 2010
Again, many thanks! I think I am nearly there!
I am getting the paint events now, but I am
not seeing anything painted to the QImage when
I call render().
I noticed that qimage->paintEngine()->painter()
sometimes returns null which seemed strange, so
I have added a test to prevent a fault (line 20).
I have attached my test code. After waiting for
3 seconds for the webpage to render, it saves
the qimage to 'output.png' and exits.
All I see in the output is the white background!
Have I missed anything?
Richard.
Richard Hosking wrote:
> Many thanks for the advice. The repaintRequested approach seems to
> be the ideal method for me.
>
> I have implemented this, but I am getting Painter errors:-
>
> "A paint device can only be painted by one painter at a time"
>
> ...when painting to the QImage upon each repaintRequested call.
> I suspect some concurrency issues here on my part!
>
> I have attached my very stripped down test code which highlights
> my issue. What do I need to do to make this work? Do I need to
> 'queue' the paint events myself so they do not overlap?
>
> Richard.
>
> (Qt 4.5.1 on Ubuntu 9.04)
>
> Girish Ramakrishnan wrote:
>> 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.
>>
>>
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QImageWebRendererTest.cpp
Type: text/x-c++src
Size: 1208 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100101/304a0f3c/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QImageWebRendererTest.h
Type: text/x-chdr
Size: 559 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100101/304a0f3c/attachment-0001.bin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: QImageWebRendererTest.pro
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100101/304a0f3c/attachment.pl
More information about the Qt-interest-old
mailing list