I have a Qt application that launches Webviews using QWebChannel
.
In these views, I have the JavaScript doing some stuff in order to position/resize the window depending on the screen size. The screen
object is supposed to give this kind of information. (screen doc)
But in my QWebEnginePage
, the screen object is empty during the whole loading process.
If I put a listener on a button to get screen.height
somewhere on the page, now it works.
//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
});
});
So my question is, how can I access screen
values at some point in my JavaScript?