pythonpyqt5qt-designerqtwebview

How to get QtWebKitWidgets.QWebView to work with qt designer


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


Solution

  • 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).