当前位置: 代码网 > it编程>编程语言>C/C++ > Qt qml实现动态轮播图效果

Qt qml实现动态轮播图效果

2024年12月30日 C/C++ 我要评论
一、效果展示二、源码分享dynamiccarousel.qmlimport qtquickimport qtquick.controlsimport qtquick.layoutsimport qtq

一、效果展示

二、源码分享

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动态轮播图内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com