PDA

View Full Version : QWebView with .css, .js and images in a resource file...



sublimer
10th September 2010, 21:26
Hello, I have a .qrc file with a .css, a .js and some images in it that I would like to be able to include in a QWebView object.

I have a string of HTML code with references to the aforementioned file types but when I call setHtml, all it does is display the text in their HTML tables without the styling or images that I want it to have.

For this application, saving the webpage first is not appropriate, I am giving the user a preview of the page before they can save it.

I am using 4.6 and any suggestions or example would be much appreciated, I did some searching first with minimal luck.

rowinggolfer
14th September 2010, 13:27
I have a string of HTML code with references to the aforementioned file types but when I call setHtml,

You need to set a base url of 'qrc:/' when you call setHtml.

here's a pyQt4 example


import qrc_resources
from PyQt4 import QtCore
from PyQt4.QtWebKit import QWebView

wv = QWebView()
wv.show()
html = "<body><img src='mypicture.png' /></body>"
wv.setHtml(html, QtCore.QUrl('qrc:/'))


incidentally, having a full path of 'qrc:/mypicture.png' within the html also works.