【发布时间】:2019-01-21 15:34:33
【问题描述】:
我已经实现了一个类似于 Itunes 的封面流程。但是,即使在研究和阅读文档之后,我仍然无法解决一件事...... 我有以下结果,但我只想显示一半的反射。
我发现了以下 StackOverflow 帖子:How do I make a gradient opacity in an image - 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
}
}
欢迎任何想法 :) 我试图使我的帖子尽可能清晰,但如果有什么需要理解的地方,请询问:)
【问题讨论】:
-
理解这些东西我有点分心,你可以放置输入图像和另一个你想要的输出图像。 :-)