How to display QPixmap on a canvas element in a QWebView window?



  • I'm experimenting with QtWebKitBridge and have a basic testbed working. I have a Qt form with a button that loads a file from disc into a QPixmap and the embedded QWebView then loads that QPixmap into an <img> tag.. This much works.

    I drill into my webview:
    ui->myWebView->page()->mainFrame()->evaluateJavaScript("loadImage()");

    loadImage() is a javascript function that does the following to load the QPixmap into an img element:

    myQtCanvasTest1.myPixmap.assignToHTMLImageElement(document.getElementById("imageElement"));

    This works exactly as I'd expect.. The image that was loaded in the Qt context is displayed in the embedded webKit browser in "imageElement"

    But I don't want it on an image element, I want it on an html5 canvas element

    So if in my HTML, I also include:
    <canvas id="myCanvas" width="400" height="410"></canvas>

    Then how do I load my QPixmap into the canvas?

    I tried the following, but it crashes:--
    var context = document.getElementById("myCanvas").getContext("2d");
    context.putImageData(myQtCanvasTest1.myPixmap.toImageData());

    Thanks


Log in to reply
 

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