2

I want to integrate/show a web page (url) section on my main window. I use anaconda, pyqt (5.6) and designer. I added a QWebView on my main form via designer. But I can't run it. The error I get when I try to run the main window is:

self.webView_test = QtWebKitWidgets.QWebView(self.centralwidget)
NameError: name 'QtWebKitWidgets' is not defined

I did some research and there are lots of similar posts. It seems QtWebKitWidgets (and also QtWebKit) is no longer available (deprecated). This is confusing since I have the QWebView option via designer.

I am looking for an answer that will solve the problem without having to reinstall pyqt or any other major changes. Though I am okay to install something (package/module) from anacondas web site etc. I want to do the gui aspect completely from designer so if there is a way, please provide me some help.

ref:

NameError: name 'QWebPage' is not defined

https://github.com/conda-forge/pyqt-feedstock/issues/19

shafuq
  • 465
  • 6
  • 20
  • 1
    check the py file generated otherwise simply add from PyQt5 import QtWebKitWidgets – Nimish Bansal Jan 07 '18 at 12:24
  • @ Nimish Bansal, The error went away but I cant see the QWebView interface to check if it is working properly. So I added this line of code: self.ui.webView_test.load(QtCore.QUrl("https://www.google.com")). It gave me an error regarding QtCore. What is the proper way for me to add the url so I can check the solution? I am using another py file to control the designer default py fyi. – shafuq Jan 07 '18 at 12:31
  • add the code as much as possible – Nimish Bansal Jan 07 '18 at 12:32
  • I changed the line to: self.ui.webView_test.load(QUrl("https://www.google.com")) and it worked! Also I added QUrl to be imported. Please add your comment as an answer so I can accept. Thank you! ( – shafuq Jan 07 '18 at 12:37
  • No Problem .You solved it on your own :) – Nimish Bansal Jan 07 '18 at 12:38

1 Answers1

0

It seems the answer was pretty simple. Thanks to @Nimish Bansal the following solved it:

Just add the line:

from PyQt5 import QtWebKitWidgets

Into the original py file generated by pyuic. You have to keep (this change) in mind for every time you modify the window designer. It doesn't add that line automatically. That's it!

Edit: I just noticed that the line (import) does come with pyuic. BUT it falls under the main codes in the UI file - not at the top. I always comment that section out so I didn't even notice it till now. All you have to do is cut the line their (the same one I provided) and move it to the top (where the other imports are).

shafuq
  • 465
  • 6
  • 20