How would you display a local html file using the Qt resource system? The obvious QtCore.QUrl.fromLocalFile(":/local_file.html") doesn’t seem to be the correct syntax.
File mainwindow.qrc (before compilation)
<qresource prefix="/">
<file alias="html_home">webbrowser_html/program_index.html</file>
File ui_mainwindow:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
#...
self.WebBrowser = QtWebKit.QWebView(self.Frame3)
File webbrower.py
from ui_mainwindow import Ui_MainWindow
import mainwindow_rc
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
#...
stream = QtCore.QFile(':/webbrowser_html/program_index.html')
if stream.open(QtCore.QFile.ReadOnly):
home_html = QtCore.QString.fromUtf8(stream.readAll())
self.WebBrowser.setHtml()
stream.close()
QUrlrequires a scheme, and for resources it isqrc://. Relevant part from the docs:So, use this instead:
Edit
You are giving the file an
alias(alias="html_home"):Path is now
:/html_home, not:/webbrowser_html/program_index.htmlYou should use:
Which would be in your case:
(You should adjust the ekhumoro’s solution too, if you intend to use that. Also note that you are not setting the HTML of the page in your paste.)