我已经开始将一些 QWebView 小部件嵌入到我的桌面应用程序 (PyQt) 中。
我使用 JQuery 和 CSS 来增强外观和可用性。
使用 Web 检查器调试我的 html 代码会很舒服。
如何将 Firebug Lite 嵌入到我的 QWebView 小部件中?
例如我尝试了以下代码,但它不起作用:
html1 = """
<html debug="true">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js#startOpened=true"></script>
<script type="text/javascript">
$(document).ready(function() {
$("body").css("background", "#f00");
console.log("in here");
});
</script>
</head>
<body><h1>Hello!</h1></body>
</html>
"""
html2 = """
<html debug="true">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("body").css("background", "#f00");
var firebugLite = document.createElement("script");
firebugLite.src = "https://getfirebug.com/firebug-lite.js";
firebugLite.id = "firebug_lite";
firebugLite.textContent = "{ startOpened: true }";
document.getElementsByTagName("head")[0].appendChild(firebugLite);
console.log("in here");
});
</script>
</head>
<body><h1>Hello!</h1></body>
</html>
"""
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QWebView()
frame = view.page().mainFrame()
frame.setHtml(html2)
view.show()
app.exec_()
html1 和 html2 效果相同:body 变成红色,但 Firebug 不显示。
附注我的实际 html 代码无法使用外部客户端浏览器进行调试,
因为它使用 QT 资源和应用程序窗口对象。
最佳答案
我已将此 JavaScript 添加到我的基于 WebKit 的项目中,也许这对 QWebView 也有帮助?
var firebugLite = document.createElement("script");
firebugLite.src = "https://getfirebug.com/firebug-lite.js";
firebugLite.id = "firebug_lite";
firebugLite.textContent = "{ startOpened: true }";
document.getElementsByTagName("head")[0].appendChild(firebugLite);
关于debugging - 如何在我的 QWebView 小部件中嵌入 Firebug Lite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6398262/