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?
-
You'd probably need to profile it and see where the time is spent.Kuba hasn't forgotten Monica– Kuba hasn't forgotten Monica2015-08-08 18:33:58 +00:00Commented Aug 8, 2015 at 18:33
-
@KubaOber I did that and the drop in frame rate, happens exactly when I resize the SplitView (changing the width of the WebView) when its updateLayout() and moveHandle() functions are triggered.reckless– reckless2015-08-08 18:41:14 +00:00Commented Aug 8, 2015 at 18:41
1 Answer
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.
5 Comments
scale or using Scale object is all you need. For more information see my edited answer. If you are still not satisfied please provide simple example of code you want to work without lag.