TraceCanvas QML Type

一种专门的画布类型,用于渲染跟踪对象。更多

Import Statement: import QtQuick.VirtualKeyboard.Styles
Since: QtQuick.VirtualKeyboard 2.0
Inherits:

Canvas

属性

信号

  • onRecycle(var traceCanvas) (since QtQuick.VirtualKeyboard.Styles 6.1)

方法

详细说明

该类型提供在屏幕上渲染跟踪对象的功能。

要在键盘中使用跟踪渲染,必须将此类型声明为KeyboardStyle.traceCanvasDelegate 组件。

traceCanvasDelegate: TraceCanvas {
}

自定义绘图属性可在 Canvas.available 信号中初始化。例如

onAvailableChanged: {
    if (!available)
        return;
    var ctx = getContext("2d")
    ctx.lineWidth = 8 * scaleHint
    ctx.lineCap = "round"
    ctx.strokeStyle = Qt.rgba(0xFF, 0xFF, 0xFF)
    ctx.fillStyle = ctx.strokeStyle
}

该类型提供内置的跟踪呈现选项。目前有以下渲染选项:

  • renderSmoothedLine 渲染圆角平滑线(默认值)

可通过renderFunction 属性更改渲染功能。

renderFunction: renderSmoothedLine

还支持自定义渲染功能。请看下面的示例:

renderFunction: renderCustomLine

function renderCustomLine() {
    getContext("2d")
    var points = trace.points()

    ...
}

属性文档

autoDestroy : bool

启用自动销毁模式。

如果启用,该项目将在trace 对象销毁时销毁。

默认值为 false。在这种情况下,画布可在onRecycle 信号触发后重新使用。


autoDestroyDelay : int

指定对象被销毁或回收之前的大致延迟时间(从自动销毁开始算起,以毫秒为单位)。

例如,通过该延迟,可以在销毁前为对象制作动画。

默认值为 0。


renderFunction : var

该属性定义了渲染功能。

默认值为 0。renderSmoothedLine


trace : Trace

提供对Trace 对象的访问。


信号文档

[since QtQuick.VirtualKeyboard.Styles 6.1] onRecycle(var traceCanvas)

traceCanvas 被回收时发出。

注: 相应的处理程序是onOnRecycle

该信号在 QtQuick.VirtualKeyboard.Styles 6.1 中引入。


方法文档

[since QtQuick.VirtualKeyboard.Styles 6.1] recycle()

通过清除所有绘图和重置变量来回收跟踪画布。

函数完成后(返回前)会触发onRecycle 信号。

回收成功后,函数返回 true。

此方法在 QtQuick.VirtualKeyboard.Styles 6.1 中引入。


[since QtQuick.VirtualKeyboard.Styles 6.1] renderClear()

清除屏幕并重置渲染。

此方法在 QtQuick.VirtualKeyboard.Styles 6.1 中引入。


renderSmoothedLine()

渲染圆角平滑线。

此函数是增量函数,仅渲染添加到跟踪中的新部分。

此函数不会更改任何画布属性(即这些属性可在其他地方设置。)


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.