QML实现酷炫的 Cover Flow 效果(PathView)
生活随笔
收集整理的這篇文章主要介紹了
QML实现酷炫的 Cover Flow 效果(PathView)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
在 QML 中的 PathView 來實現一個 Cover Flow 圖片切換效果,非常酷炫,并且代碼也非常精簡,先來看看效果圖
源代碼
Rectangle {id:coverflowcolor:"black"property ListModel modelproperty int itemCount: 5PathView{id:pathViewmodel:coverflow.modeldelegate: Item {id:delegateItemwidth: 200height: 200z:PathView.iconZscale:PathView.iconScaleImage{id:imagesource: urlwidth: delegateItem.widthheight: delegateItem.height}ShaderEffect {anchors.top: image.bottomwidth: image.widthheight: image.height;anchors.left: image.leftproperty variant source: image;property size sourceSize: Qt.size(0.5 / image.width, 0.5 / image.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;}"}transform: Rotation{origin.x:image.width/2.0origin.y:image.height/2.0axis{x:0;y:1;z:0}angle: delegateItem.PathView.iconAngle}}path:coverFlowPathpathItemCount: coverflow.itemCountanchors.fill: parentpreferredHighlightBegin: 0.5preferredHighlightEnd: 0.5}Path{id:coverFlowPathstartX: 0startY: coverflow.height/3PathAttribute{name:"iconZ";value: 0}PathAttribute{name:"iconAngle";value: 70}PathAttribute{name:"iconScale";value: 0.6}PathLine{x:coverflow.width/2;y:coverflow.height/3}PathAttribute{name:"iconZ";value: 100}PathAttribute{name:"iconAngle";value: 0}PathAttribute{name:"iconScale";value: 1.0}PathLine{x:coverflow.width;y:coverflow.height/3}PathAttribute{name:"iconZ";value: 0}PathAttribute{name:"iconAngle";value: -70}PathAttribute{name:"iconScale";value: 0.6}PathPercent{value:1.0}}}這里用ShaderEffect來實現圖片的陰影倒影效果,之前的博客里面有介紹
Path中主要通過修改圖片的 Z 值、縮放、以及旋轉來改變圖片屬性達到我們想要的效果。
源碼在這里,點擊下載
本文參考http://www.qter.org/portal.php?mod=view&aid=20
總結
以上是生活随笔為你收集整理的QML实现酷炫的 Cover Flow 效果(PathView)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QML 发光呼吸动画字体
- 下一篇: QGraphicsItem获取不到鼠标事