python - PySide 网络浏览器出现,但检查器不显示任何内容

标签 python qt webkit pyside

我目前正在运行这段代码,虽然出现了网络浏览器,但网络检查器似乎没有显示任何内容,我是不是做错了什么?

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_())

关于python - PySide 网络浏览器出现,但检查器不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5942487/

相关文章:

python - 尝试从多个位置导入模块的更简洁的方法?

c++ - 具有 3 种可能值的图像

css - iOS 和 Safari 中 CSS `currentColor` 关键字的问题

javascript - 通过[]访问的字符串中的字符是字符串吗?

python - 具有多个 for 子句的列表理解的 Map/reduce 等价物

python - 添加 "+"和 "-"的最佳方法?

python - 使用 BeautifulSoup 和 Python 抓取多个页面

qt - CMake : Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)

python - 安装 PyQt

html - 可以将 html 元素标记为仅使用浏览器的默认 css 吗?