[Qt-interest] QWebView: howto embed a QPixmap into HTML code [Solved]
Ulf-Alexander v. Ceumern-Lindenstjerna
ceumern at vrmagic.com
Mon Mar 29 15:18:43 CEST 2010
Okay, after some research I managed to find a solution to my problem:
// use QByteArray to embed the images into the HTML as a base64 encoded string
QByteArray byteArray;
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
buffer.open(QIODevice::WriteOnly);
pixmap->save(&buffer, "PNG");
html += "<img src=\"data:image/png;base64," + byteArray.toBase64() + "\">";
webView->setHtml(html);
Works like a charm!
Cheers, Ulf
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Ulf-Alexander v. Ceumern-
> Lindenstjerna
> Sent: Monday, March 29, 2010 10:58 AM
> To: Qt-interest
> Subject: [Qt-interest] QWebView: howto embed a QPixmap into HTML code
>
> Hi everyone,
>
> I managed to get QWebView to load an image from the resource system via
> QWebView::setHtml(html, QUrl("qrc:/"));
>
> Now I am facing another problem: I have a runtime-generated QPixmap
> that I want to display in the QWebView. Is there any way to achieve
> that other than saving it on the local file system?
>
> Regards, Ulf
>
> --
> Ulf v. Ceumern
> Dipl.-Inf.
>
> VRmagic GmbH
> Augustaanlage 32
> 68165 Mannheim, Germany
> E-Mail: ceumern at vrmagic.com
>
> Tel.: +49/621/400416-52
> Fax: +49/621/400416-99
>
>
> Steuernummer: 38189/54003
> USt.IdNr.: DE217365947
> Registergericht: Amtsgericht Mannheim, HRB 8958
> Geschäftsführer: Norbert Hinckers, Dr. Markus Schill
> --
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list