本页内容

TraceCanvas QML Type

一种用于渲染 Trace 对象的专用 Canvas 类型。更多内容...

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

Canvas

属性

信号

方法

详细说明

此类型提供了在屏幕上渲染 Trace 对象的功能。

若要在键盘中启用 Trace 渲染功能,必须将此类型声明为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
}

该类型为 Trace 渲染提供了内置选项。目前可用的渲染选项如下:

  • renderSmoothedLine 渲染带圆角的平滑线条(默认)

可通过renderFunction 属性更改渲染函数。

renderFunction: renderSmoothedLine

同时也支持自定义渲染函数。请参阅以下示例:

renderFunction: renderCustomLine

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

    ...
}

属性文档

autoDestroy : bool

启用自动销毁模式。

如果启用此选项,当trace 对象被销毁时,该项也将被销毁。

默认值为 false。在此情况下,触发onRecycle 信号后,该画布可被重复使用。

autoDestroyDelay : int

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

例如,此延迟使得可以在销毁前对该项进行动画处理。

默认值为 0。

renderFunction : var

此属性定义了渲染函数。

默认值为renderSmoothedLine

trace : Trace

提供对Trace 对象的访问。

Signal 文档

[since 6.1] onRecycle(var traceCanvas)

当traceCanvas 被回收时触发。

注意: 对应的处理程序 是onOnRecycle 。

该信号在 Qt 6.1 中引入。

方法文档

[since 6.1] recycle()

通过清除所有绘图并重置变量来回收 trace 画布。

该函数在执行完成后(返回之前)触发onRecycle 信号。

若回收成功,该函数返回 true。

该方法在 Qt 6.1 中引入。

[since 6.1] renderClear()

清除屏幕并重置渲染。

该方法在 Qt 6.1 中引入。

renderSmoothedLine()

绘制具有圆角的平滑线条。

此函数为增量式,仅渲染新增至“Trace”的部分。

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

© 2026 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.