を使用して Webviews を起動する Qt アプリケーションがありますQWebChannel
。
これらのビューでは、画面サイズに応じてウィンドウを配置/サイズ変更するために、JavaScript で何らかの処理を行っています。screen
オブジェクトは、この種の情報を提供することになっています。(画面ドキュメント)
しかし、私の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
});
});
私の質問は、screen
JavaScript のある時点で値にアクセスするにはどうすればよいですか?