一、效果展示

二、源码分享
dynamiccarousel.qml
import qtquick
import qtquick.controls
import qtquick.layouts
import qtquick.shapes
item {
id:self
signal clearerror(string numberstr)
pathview{
id:pathview
anchors.fill: parent
focus: true
clip: true
model:listmodel
delegate:listdelegate
path: listpath
preferredhighlightbegin: 0.5
preferredhighlightend: 0.5
pathitemcount: 3
mousearea{
anchors.fill: parent
hoverenabled: true
cursorshape: qt.pointinghandcursor
onentered: {
timercircle.stop()
}
onexited: {
timercircle.start()
}
}
}
listmodel{
id:listmodel
listelement{number:"000";note:"伺服电机故障";solution:"请联系管理员"}
listelement{number:"111";note:"卡件";solution:"清除线体后重新启动"}
listelement{number:"222";note:"等待处理";solution:"请联系管理员"}
listelement{number:"333";note:"等待处理";solution:"请联系管理员"}
listelement{number:"444";note:"等待处理";solution:"请联系管理员"}
listelement{number:"555";note:"等待处理";solution:"请联系管理员"}
}
component{
id:listdelegate
rectangle{
width: pathview.width
height: pathview.height*1.2
color: "#f013227a"
radius: 15
border.width: 2
z:pathview.z?pathview.z:0
scale: pathview.scale?pathview.scale:1.0
required property string number
required property string note
required property string solution
rowlayout{
anchors.fill: parent
anchors.margins: 5
columnlayout{
layout.fillwidth: true
layout.fillheight: true
text {
id: texterrornumber
layout.fillwidth: true
layout.fillheight: true
text: number
font.pointsize: 16
verticalalignment: qt.alignvcenter
horizontalalignment: qt.alignhcenter
color: "#ffffffff"
}
text {
layout.fillwidth: true
layout.fillheight: true
id: texterrornote
text: note
font.pointsize: 12
verticalalignment: qt.alignvcenter
horizontalalignment: qt.alignhcenter
color: "#ffffffff"
}
text {
layout.fillwidth: true
layout.fillheight: true
id: texterrorsolution
text: solution
font.pointsize: 12
verticalalignment: qt.alignvcenter
horizontalalignment: qt.alignhcenter
color: "#ffffffff"
}
}
button{
id:btnclearerror
layout.preferredwidth: parent.width/5
layout.preferredheight: parent.width/5
hoverenabled: false
scale: down?0.8:1.0
background: rectangle{
radius: 10
border.width: 0
color: "#00000000"
image {
anchors.fill: parent
source:"qrc:/image/resources/images/qml/clearerror.svg"
}
}
onclicked: {
clearerror(texterrornumber.text)
listmodel.remove(pathview.currentindex)
}
}
}
}
}
path{
id:listpath
startx: 0
starty:pathview.height/2
pathattribute{name:"z";value:0}
pathattribute{name:"scale";value:0.5}
pathline{
x:pathview.width/2
y:pathview.height/2
}
pathattribute{name:"z";value:2}
pathattribute{name:"scale";value:0.8}
pathline{
x:pathview.width
y:pathview.height/2
}
pathattribute{name:"z";value:0}
pathattribute{name:"scale";value:0.5}
}
timer{
id:timercircle
running: true
repeat: true
interval: 3000
ontriggered: {
pathview.incrementcurrentindex()
}
}
//listelement{number:"1121";note:"等待处理";solution:"请联系管理员"}
function adderror(numberstr,notestr,solutionstr){
var data = {number: numberstr,note:notestr,solution:solutionstr};
listmodel.append(data)
}
}
三、使用方法
dynamiccarousel{
anchors.fill: parent
anchors.margins: 5
anchors.horizontalcenter: parent.horizontalcenter
}
四、实现原理
通过pathview实现,通过路径和缩放来实现动态效果。
到此这篇关于qt qml实现动态轮播图效果的文章就介绍到这了,更多相关qt qml动态轮播图内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论