问题
I created simple project for displaying local .html page.
I used Qt5.4 with QWebView
there. But after switching to Qt5.6 I noticed
that Qt WebKit is deprecated and not supported any more.
Thus I decided to replace Qt WebKit functionality with one from the
Qt WebEngine.
After replacing QWebView
with QWebEngineView
I investigated that setZoomFactor
method has no effect.
Is it known issue? How can I handle with this?
EDIT:
An interesting thing have been investigated recently. I use setHtml
method for setting content of local .html files to my QWebEngineView
. These files also contain references to images. So I set baseUrl parameter as a relative path to required images. In that case using of setZoomFactor
method has no effect.
But when I don't set relative path to images as parameter, images are absent on QWebEngineView
but zoom functionality works. Any ideas what is wrong here?
回答1:
It seems to be a known bug in this version of Qt. You can check by yourself here : Qt Bug 51992.
Basically, it is said that :
This looks like a known glitch that is currently happening because of the Chromium API that we use for setting the zoom factor.
And also :
Chromium limits the zoom factor to a maximum of 5.0 - any calls with a number higher than that will have no effect.
Hope that will help you.
回答2:
Setting zoomFactor for QML WebEngineView in Qt 5.11 using QML zoomFactor property or C++ setZoomFactor (private-API) did not work as expected. I discovered from comments in QT Bug 51992 that it works when set after a page load.
QML solution:
WebEngineView {
// ...
onLoadingChanged: {
zoomFactor = 0.75
}
}
QWebEngineView solution: connect to the loadFinished
signal, and set zoomFactor after each page load:
main.cpp (after engine.load call):
QWebEngineView *webView; // = ...
QObject::connect(webView, &QWebEngineView::loadFinished,
[=](bool arg) {
webView->setZoomFactor(zoomFactor);
});
来源:https://stackoverflow.com/questions/36518896/zoom-feature-for-qwebengine-does-not-work