Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the contentSize of a web page in Qt5.4-QtWebEngine

I'm using the new Qt5.4 with the module QtWebEngine and from what I see mainFrame() doesn't exists anymore. How to get the contentSize/size of the page and how to render it now? I tried with the setView and view but doesn't work.

like image 656
000571245 Avatar asked Nov 02 '25 01:11

000571245


2 Answers

I couldn't find any native Qt method for that, but I came up with a workaround: once the page is loaded, I do the following to resize my widget to the web content:

webView->page()->runJavaScript("document.documentElement.scrollWidth;",[=](QVariant result){
int newWidth=result.toInt()+10;
webView->resize(newWidth,webView->height());
});

webView->page()->runJavaScript("document.documentElement.scrollHeight;",[=](QVariant result){
int newHeight=result.toInt();
webView->resize(webView->width(),newHeight);
});

NB: I added a 10px width margin

like image 57
Robin Lobel Avatar answered Nov 04 '25 18:11

Robin Lobel


Check if the QWebEnginePage::geometryChangeRequested signal does what you want.

Also you display a QWebEnginePage by creating a QWebEngineView (it's a QWidget) and calling QWebEngineView::setPage(yourPage).

like image 40
dom0 Avatar answered Nov 04 '25 16:11

dom0