Nominate our 2022 Qt Champions!

Does using QPainter to "copy" a canvas embedded in QWebView copy or share memory?

  • I have a QWebView loaded with an HTML page that has a canvas element called canvas0. (The embedded canvas occupies the entire viewport)

    When I do the following, is there a full copy operation happening under the hood or does this share memory?

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

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


    I'm doing that so that I can then use QImage to get the pixel value at the mouse position:

    QRgb rgbVal = image.pixel(mouseEvent->x(), mouseEvent->y());

    If I do that on each mousemove event, and it's copying and not sharing memory, I worry about performance.. Perhaps there is a better way for me to get the pixel value at the mouse-location from the QWebView widget itself?

Log in to reply