渐变

演示了如何在QPainter 中使用渐变。

一款用于应用渐变效果的、具有多种设置选项的应用程序

渐变有三种类型:

  • 线性渐变在起始点和终点之间进行颜色插值。
  • 径向渐变在焦点与围绕该焦点的圆周上的点之间进行颜色插值。
  • 锥形渐变在中心点周围进行颜色插值。

右侧面板包含一个颜色表编辑器,用于定义渐变中的颜色。最上方的三个控件分别控制红、绿、蓝三原色,而最后一个控件则控制渐变的透明度。您可以通过单击鼠标左键来移动或添加新点,通过单击鼠标右键来删除点。

页面底部提供了三个示例配置,作为颜色表配置方式的参考。

Qt 还提供了一套命名的渐变预设。这些预设基于开源的 WebGradients 集合。点击“预设”框中的名称即可显示该渐变。使用箭头按钮可浏览可用的预设。

示例项目 @ code.qt.io

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