1

Using PySide QtWebkit, I want to show a home html page in QWebView. I tried, but I cannot render it. Here is My code:

home.html:

<!DOCTYPE html>
<html>
    <head><title>HomeStart</title></head>
    <body>
        <h3 align="center">Home Page</h3>
        <div>
            <img src="images/welcome.png"/>
        </div>
    </body>
</html>

python code:

self.view = QtWebKit.QWebView()
self.view.load("home.html")  # can not render in webkit.
# QtCore.QUrl.fromLocalFile(QtCore.QFile().fileName()))  # can not render in webkit either.  

PS: the python code file and the html file are in the same directory. But in webkit it renders it blank.

2 Answers 2

1

It makes no difference that the python code file and the html are in the same directory. What matters, is that the html file is in the current directory.

If you use an absolute path:

self.view.load("/path/to/html/files/home.html")

or change to the relevant directory first:

os.chdir("/path/to/html/files")
self.view.load("home.html")

then it should work okay.

Sign up to request clarification or add additional context in comments.

Comments

0

It works fine for me with very simple code. Maybe you have omitted something.

import sys
from PySide.QtGui import *
from PySide.QtWebKit import QWebView

class Window(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)

        self.view = QWebView(self)
        self.view.load("home.html")

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.view)

        self.setLayout(self.layout)
        self.show()

app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.