我目前正在运行这个代码,虽然Web浏览器出现,但Web检查器似乎没有显示任何东西,我做错了什么?
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_())
解决方法
是在
Qt Documentation:
Note: A QWebInspector will display a
blank widget if either: page() is null
QWebSettings::DeveloperExtrasEnabled
is false
你必须启用它,像这样:
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_())