|
1Qter豆
我想要做控件倒影特效,不是图片倒影,图片倒影已经做出来了,可是不能实现按钮控件倒影,有谁可以帮帮忙?
- import QtQuick 2.4
- import QtQuick.Window 2.2
- import QtQuick.Controls 1.4
- import QtGraphicalEffects 1.0
- Window {
- visible: true
- width: 600
- height: 500
- Rectangle {
- id: window
- width: 600
- height: 500
- gradient: Gradient {
- GradientStop { position: 0; color: "lightsteelblue" }
- GradientStop { position: 1; color: "black" }
- }
- Button{
- id: img
- width: 300
- height: 170
- text: "haha"
- anchors.centerIn: parent
- onClicked: {
- Qt.quit();
- }
- }
- // Image {
- // id: img
- // width: 300
- // height: 170
- // source: "snowman.png"
- // anchors.centerIn: parent
- // }
- ShaderEffect {
- anchors.top: img.bottom
- width: img.width
- height: img.height
- anchors.left: img.left
- property variant source: img
- property size sourceSize: Qt.size(0.5 / img.width, 0.5 / img.height)
- fragmentShader: "
- varying highp vec2 qt_TexCoord0;
- uniform lowp sampler2D source;
- uniform lowp vec2 sourceSize;
- uniform lowp float qt_Opacity;
- void main() {
- lowp vec2 tc = qt_TexCoord0 * vec2(1, -1) + vec2(0, 1);
- lowp vec4 col = 0.25 * (texture2D(source, tc + sourceSize)
- + texture2D(source, tc- sourceSize)
- + texture2D(source, tc + sourceSize * vec2(1, -1))
- + texture2D(source, tc + sourceSize * vec2(-1, 1))
- );
- gl_FragColor = col * qt_Opacity * (1.0 - qt_TexCoord0.y) * 0.2;
- }"
- }
- }
- }
复制代码
|
|