加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Pyside,webkit的基本问题

发布时间:2020-12-16 23:06:53 所属栏目:Python 来源:网络整理
导读:我目前正在运行这个代码,虽然Web浏览器出现,但Web检查器似乎没有显示任何东西,我做错了什么? import sysfrom PySide.QtCore import *from PySide.QtGui import *from PySide.QtWebKit import *app = QApplication(sys.argv)web = QWebView()web.load(QUrl("
我目前正在运行这个代码,虽然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_())

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读