Qt Canvas Painter
Qt Canvas Painter 模块提供了用于硬件加速的命令式 2D 绘图类。该绘图 API 既适用于Qt Quick ,也适用于Qt Widgets ,还可直接与QRhi 配合使用。该 API 的设计总体遵循 HTML canvas 2D 上下文规范,但在某些方面进行了精简,并在其他方面进行了补充。
与QPainter 相比,Qt Canvas Painter 结构更为精简,抽象层级更少,旨在在QRhi 上实现最佳性能。Qt Canvas Painter 专为 GPU 渲染设计,不具备QPainter 所拥有的 CPU 后端。
使用该模块
C++ API
要使用 Qt 模块的 C++ API,需要链接该模块库,可以是直接链接,也可以通过其他依赖项间接链接。包括CMake和qmake 在内的多种构建工具都对此提供了专门支持。
QML API
可通过QtCanvas2D 导入使用该模块的 QML 类型。要使用这些类型,请在您的 .qml 文件中添加以下导入语句:
import QtCanvas2D使用 CMake 进行构建
使用find_package() 命令在Qt6 包中定位所需的模块组件:
find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)更多详细信息,请参阅“使用 CMake 构建”概述。
与QCanvasCustomBrush 配合使用的着色器可通过 CMake 函数qt_add_custom_brush_shaders添加到项目中。
类参考
示例
许可和归属
Qt Canvas Painter 运行时库由The Qt Company 提供商业许可。此外,它还遵循GNU 通用公共许可证第 3 版。
更多详细信息请参阅Qt 许可协议。
此外,6.12.0 版本中的 Qt Canvas Painter 可能包含遵循以下宽松许可证的第三方模块:
zlib 许可协议 |
© 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.