如何在 QML WebView 中禁用渲染? [英] How to disable rendering in QML WebView?

查看:58
本文介绍了如何在 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?

推荐答案

不是改变 widthheight 属性而是改变 scale 属性WebView.

Instead of changing the width and height properties change scale property of the WebView.

  • 在开始调整大小时保存widthheight 的初始值.
  • 调整大小时不要改变widthheight.而是在调整大小开始时将 scale 设置为 newWidth 除以宽度.
  • 当调整大小结束时,为这些属性设置新的 widthheight 值,并将 scale 设置为 1.
  • At beginning of the resize save initial values of width and height.
  • On resize don't change width and height. Instead set scale to newWidth divided by width at beginning of the resize.
  • When resize ends set new values of width and height to these properties and set scale to 1.

由于您无法控制 widthheight 属性,您可以将 WebView 替换为 Rectangle 并将颜色设置为透明".然后你可以把WebView放在Rectangle上,观察Rectanglewidthheight正在改变.

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 毫秒.每次Rectanglewidthheight发生变化时,重新启动Timer并更新scale.当Timer被触发时,设置真正的widthheight.

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.

如果矩形的widthheight 的比例不是恒定的,则使用QML 对象Scale.有了它,您可以独立更改 xScaleyScale.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆