[SOLVED] can I get an image from an embedded HTML5 Canvas into a QWidget?

  • Hi

    I have a QWebView widget and the page which it loads contains an embedded HTML5 canvas element which shows a custom image/scene based on internet server data.

    On the Qt side (ie. within a slot on the main form) I'd like to "reach into" the DOM of the embedded webpage and "grab" the image data off the canvas element for further processing. I don't want the whole WebView, just the image data on the particular embedded canvas. Is this possible? If so, how?


  • using info from

    along with
    QVariant QWebFrame::evaluateJavaScript ( const QString & scriptSource ) [slot]

    you might be able to do something like


    you'll have to change the script to suit your need

  • I got it to work by doing the following to copy the embedded canvas into a QImage, from there I can do with it what I need.

    QWebElement el = myWebView->page()->mainFrame()->findFirstElement("#canvas0");

    QImage image(el.geometry().width(), el.geometry().height(), QImage::Format_ARGB32);
    QPainter painter(&image);

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.