3

QtWebKit is no longer supported in PyQt5.

Although there are alternates to some of the classes of QtWebKit in QtWebEngineWidgets. But, i couldn't find any alternate to the QWebInspector class that is available in PyQt4.

Are there any such classes OR even any other option so that i can implement web inspector using PyQt5 ?

Edit: Qt5.6 and beyond has removed QtWebKitWidgets

Ankit
  • 130
  • 3
  • 13
  • QWebInspector is available in PyQt5. http://pyqt.sourceforge.net/Docs/PyQt5/api/qwebinspector.html – eyllanesc Jan 02 '17 at 20:39
  • @eyllanesc this is what i get when i try to import the module. ImportError: No module named 'PyQt5.QtWebKitWidgets'. Actually i am using PyQt5.7 and according to this [link](http://stackoverflow.com/questions/37876987/cannot-import-qtwebkitwidgets-in-pyqt5) its been removed. – Ankit Jan 02 '17 at 21:00
  • I added an example – eyllanesc Jan 02 '17 at 21:13

2 Answers2

2

I was somewhat surprised to find that QtWebKit is making a comeback. It is still not part of Qt-5.6 or Qt-5.7, but it seems that it may continue to be maintained as separate project. This means PyQt5 can continue to support QtWebKit, even though the official Qt5 docs say it has been removed.

Depending on your platform, this probably means you will need to install some extra packages if you want to use the "new" QtWebKit module in PyQt5.

PS:

As for QtWebEngine - if you're using ubuntu/debian, it seems you will have to wait for it to be supported. See Bug #1579265.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Yeah I am using Ubuntu 16.04. Thanks for the clarification. So, basically i cannot use QtWebKit Or QtWebKitWidgets class in any way using PyQt5.7 on my machine ? – Ankit Jan 03 '17 at 12:28
  • @Ankit. Not sure why you reached that conclusion. There are already [pyqt5 webkit packages](http://packages.ubuntu.com/xenial/debug/python-pyqt5.qtwebkit-dbg) in ubuntu, so it should be possible to compile for any version you like. – ekhumoro Jan 03 '17 at 18:41
  • i installed extra packages for qtwebkit too mentioned here https://launchpad.net/ubuntu/+source/pyqt5 . But, still not working in python3 - works in python2 though – Ankit Jan 08 '17 at 12:07
  • @Ankit. You need to install [python3-pyqt5.qtwebkit](http://packages.ubuntu.com/xenial/python3-pyqt5.qtwebkit). – ekhumoro Jan 08 '17 at 17:51
  • it means i still cannot get it worked after installing the above package. Import Error still persists when using python3. Btw , i had installed pyqt5 using pip3 initially - would that make a difference ? – Ankit Jan 08 '17 at 20:19
  • @Ankit. Very likely. You should get rid of all the pip installed stuff, and only use the ubuntu packages. Then I think it should work. – ekhumoro Jan 08 '17 at 20:31
1

I show the following example to use QWebInspector in PyQt5 version 5.7.1

from PyQt5.QtCore import QUrl
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebInspector
from PyQt5.QtWidgets import QApplication, QSplitter, QVBoxLayout, QWidget


class Window(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.view = QWebView(self)
        self.view.settings().setAttribute(
            QWebSettings.DeveloperExtrasEnabled, True)
        self.inspector = QWebInspector()
        self.inspector.setPage(self.view.page())
        self.inspector.show()
        self.splitter = QSplitter(self)
        self.splitter.addWidget(self.view)
        self.splitter.addWidget(self.inspector)
        layout = QVBoxLayout(self)
        layout.addWidget(self.splitter)

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    window = Window()
    window.view.load(QUrl('http://www.google.com'))
    window.show()
    sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241