qt - 如何在图像中进行不透明度渐变?
问题描述
我已经实现了一个类似于 Itunes 的封面流程。但是我仍然无法解决一件事,即使在研究和阅读文档之后......我有以下结果,但我想只显示一半的反射。
我找到了以下 StackOverflow 帖子:如何在图像中制作渐变不透明度 - QML,这与我想要实现的非常相似。除了我的背景是渐变色之外,我无法选择白色(或作为解决方案提供的解决方案代码中最后一个 GradientStop 元素的任何纯色)。
到目前为止,这是我的代码:
Image {
id: rectDelegate
anchors.fill: parent
source: images[index % images.length]
}
ShaderEffectSource {
id: reflection
sourceItem: rectDelegate
y: sourceItem.height
width: sourceItem.width
height: sourceItem.height
transform: [
Rotation {
origin.x: reflection.width / 2
origin.y: reflection.height / 2
axis.x: 1
axis.y: 0
axis.z: 0
angle: 180
}
]
visible: reflection_visible
}
Rectangle {
anchors.fill: reflection
gradient: Gradient {
GradientStop {
position: 0.0
color: "#55ffffff"
}
GradientStop {
// This determines the point at which the reflection fades out.
position: 1
color: "#ffffff"
}
}
visible: reflection_visible
}
我试图将 ShaderEffectSource 元素嵌入到一个透明矩形内,该矩形的高度将是反射高度的一半,并将 ShaderEffectSource 剪辑在里面,但不会出现反射:/
这是代码:
Rectangle {
anchors.top: rectDelegate.bottom
color: "transparent"
width: rectDelegate.width
height: rectDelegate.height - 300
visible: reflection_visible
clip: true
border.color: "yellow"
ShaderEffectSource {
id: reflection
sourceItem: rectDelegate
y: sourceItem.height
width: sourceItem.width
height: sourceItem.height
transform: [
Rotation {
origin.x: reflection.width / 2
origin.y: reflection.height / 2
axis.x: 1
axis.y: 0
axis.z: 0
angle: 180
}
]
visible: reflection_visible
}
}
任何想法都会受到欢迎:) 我试图让我的帖子尽可能清晰,但如果有什么需要理解的地方,请询问:)
解决方案
阅读这篇文章: 如何在图像中制作渐变不透明度?- QML 或者你可以使用 Canvas 类型来绘制透明渐变的图像,但正确的方法是第一种。
推荐阅读
- vba - VBA执行完整循环
- jquery - 使用 bootstrap-float-label css 引导输入密码显示隐藏
- visual-studio-code - 我无法使用新的应用程序链接语法打开 Visual Studio Code 工作区
- python - 使用可变 obj 转换为列表推导
- kotlin-exposed - 当使用 Exposed 的方法“createMissingTablesAndColumns”时,我得到一个 NoSuchElementException
- c# - 如何以编程方式设置按钮样式(第 2 部分)?
- nginx - nginx转发同域请求
- pyqt5 - PyQt5 获取具有多个值的输入
- puppeteer - 如何记录发送到 Puppeteer/Chrome 开发者的每个事件
- math - 使用 DrRacket(方案)在偶数个垫子上跳蛙