Pyside,webkit 基本问题 [英] Pyside, webkit basic question

查看:78
本文介绍了Pyside,webkit 基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

Qt 文档:

注意:QWebInspector 将显示一个空白小部件,如果: page() 为空QWebSettings::DeveloperExtrasEnabled是假的

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

这篇关于Pyside,webkit 基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆