如何在 QML WebView 中禁用渲染? [英] How to disable rendering in QML WebView?
问题描述
我目前正在构建一个使用 QML WebView
(import QtWebKit 3.0
) 的应用程序.用户需要经常调整 WebView
的大小(我使用的是 QML SplitView
),但是这会导致 UI 在应用程序窗口调整大小时极度滞后.有什么办法可以防止这种情况吗?
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?
推荐答案
不是改变 width
和 height
属性而是改变 scale
属性WebView
.
Instead of changing the width
and height
properties change scale
property of the WebView
.
- 在开始调整大小时保存
width
和height
的初始值. - 调整大小时不要改变
width
和height
.而是在调整大小开始时将scale
设置为 newWidth 除以宽度. - 当调整大小结束时,为这些属性设置新的
width
和height
值,并将scale
设置为 1.
- At beginning of the resize save initial values of
width
andheight
. - On resize don't change
width
andheight
. Instead setscale
to newWidth divided by width at beginning of the resize. - When resize ends set new values of
width
andheight
to these properties and setscale
to 1.
由于您无法控制 width
和 height
属性,您可以将 WebView
替换为 Rectangle
并将颜色设置为透明"
.然后你可以把WebView
放在Rectangle
上,观察Rectangle
的width
和height
正在改变.
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.
现在有两件事.
如果您不知道调整大小何时开始以及何时结束,请使用 Timer
间隔,例如 100 毫秒.每次Rectangle
的width
和height
发生变化时,重新启动Timer
并更新scale
.当Timer
被触发时,设置真正的width
和height
.
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
.
如果矩形的width
和height
的比例不是恒定的,则使用QML 对象Scale
.有了它,您可以独立更改 xScale
和 yScale
.
If ratio of width
and height
of Rectangle is not constant use QML object Scale
. With it you can change xScale
and yScale
independently.
这篇关于如何在 QML WebView 中禁用渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!