问题
I am currently building an application that makes use of QML WebView (import QtWebKit 3.0). The users need to resize the WebView very often (I am using a QML SplitView), however this leads to the UI to lag extremely whenever the app window is resized. Is there any way to prevent this?
回答1:
Instead of changing the width and height properties change scale property of the WebView.
- At beginning of the resize save initial values of
widthandheight. - On resize don't change
widthandheight. Instead setscaleto newWidth divided by width at beginning of the resize. - When resize ends set new values of
widthandheightto these properties and setscaleto 1.
EDIT:
Since you don't have control of width and height properties you can replace WebView with Rectangle with color set to "transparent". Then you can place WebView on Rectangle and watch how width and height of Rectangle are changing.
Now two things.
If you don't know when resize starts and when ends use Timer with interval for example 100ms. Restart Timer and update scale every time width and height of Rectangle changes. When Timer is triggered set real width and height.
If ratio of width and height of Rectangle is not constant use QML object Scale. With it you can change xScale and yScale independently.
来源:https://stackoverflow.com/questions/31896264/how-to-disable-rendering-in-qml-webview