【发布时间】:2016-08-13 05:46:32
【问题描述】:
我有一个使用 QWebChannel 启动 Webviews 的 Qt 应用程序。
在这些视图中,我让 JavaScript 做一些事情,以便根据屏幕大小定位/调整窗口大小。 screen 对象应该提供这种信息。 (screen doc)
但在我的QWebEnginePage 中,整个加载过程中屏幕对象是空的。
如果我在按钮上放置一个侦听器以在页面上的某个位置获取screen.height,现在它可以工作了。
//js local file called in html head
//screen = {}
document.addEventListener("load", function(event) {
//screen = {}
new QWebChannel(qt.webChannelTransport, function(channel) {
//screen = {}
//stuff
channel.object.myClass.show(function(res){ //Qt function that calls the show() method of the QWebEngineView
//screen = {}
});
});
document.getElementById("myBtn").addEventListener("click", function(){
console.log("height:" + screen.height); // screen: 1440
});
});
所以我的问题是,如何在我的 JavaScript 中的某个时刻访问 screen 值?
【问题讨论】:
标签: javascript qt qtwebkit qtwebengine