12

I am currently running this code, and although the web browser appears, the web inspector doesn't seem to display anything, am i doing something incorrectly?

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

app = QApplication(sys.argv)

web = QWebView()
web.load(QUrl("http://www.google.com"))
web.show()

inspect = QWebInspector()
inspect.setPage(web.page())
inspect.show()

sys.exit(app.exec_())
Sylvester Kruin
  • 3,294
  • 5
  • 16
  • 39
  • From PySide Mailing List 'Hi, You have to enable the developer extras for the QWebView. inspect = QWebInspector() page = web.page() main_frame = page.mainFrame() # Enable the Web Inspector web_settings = view.settings() web_settings.setAttribute(QtWebKit.QWebSettings.DeveloperExtrasEnabled, 1) inspect.setPage(page) inspect.show() Dom' –  May 09 '11 at 21:32

1 Answers1

16

It is in the Qt Documentation:

Note: A QWebInspector will display a blank widget if either: page() is null QWebSettings::DeveloperExtrasEnabled is false

You must enable it, like this:

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

app = QApplication(sys.argv)

web = QWebView()
web.settings().setAttribute(
    QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
# or globally:
# QWebSettings.globalSettings().setAttribute(
#     QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)

web.load(QUrl("http://www.google.com"))
web.show()

inspect = QWebInspector()
inspect.setPage(web.page())
inspect.show()

sys.exit(app.exec_())
abbot
  • 27,408
  • 6
  • 54
  • 57
  • If you find `QWebSettings.WebAttribute.DeveloperExtrasEnabled` not work, please try `QWebSettings.DeveloperExtrasEnabled`!!! (anyone explains why?) – ch271828n Jan 26 '17 at 10:06