Qt qml實(shí)現(xiàn)動態(tài)輪播圖效果
一、效果展示
二、源碼分享
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:"伺服電機(jī)故障";solution:"請聯(lián)系管理員"} ListElement{number:"111";note:"卡件";solution:"清除線體后重新啟動"} ListElement{number:"222";note:"等待處理";solution:"請聯(lián)系管理員"} ListElement{number:"333";note:"等待處理";solution:"請聯(lián)系管理員"} ListElement{number:"444";note:"等待處理";solution:"請聯(lián)系管理員"} ListElement{number:"555";note:"等待處理";solution:"請聯(lián)系管理員"} } 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:"請聯(lián)系管理員"} 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 }
四、實(shí)現(xiàn)原理
通過PathView
實(shí)現(xiàn),通過路徑和縮放來實(shí)現(xiàn)動態(tài)效果。
到此這篇關(guān)于Qt qml實(shí)現(xiàn)動態(tài)輪播圖效果的文章就介紹到這了,更多相關(guān)Qt qml動態(tài)輪播圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C數(shù)據(jù)結(jié)構(gòu)之單鏈表詳細(xì)示例分析
以下是對C語言中的單鏈表進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過來參考下2013-08-08淺談CMake配置OpenCV 時靜態(tài)鏈接與動態(tài)鏈接的選擇
下面小編就為大家?guī)硪黄獪\談CMake配置OpenCV 時靜態(tài)鏈接與動態(tài)鏈接的選擇。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01C++中獲取UTC時間精確到微秒的實(shí)現(xiàn)代碼
本篇文章是對C++中獲取UTC時間精確到微秒的實(shí)現(xiàn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05關(guān)于PCL出現(xiàn)"無法找到?pcl_commond.dll?文件程序無法執(zhí)行"的問題及解決方法
這篇文章主要介紹了PCL出現(xiàn)"無法找到?pcl_commond.dll?文件程序無法執(zhí)行"的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07VS Code 中安裝運(yùn)行、編寫C語言程序的詳細(xì)教程
這篇文章主要介紹了VS Code 中安裝運(yùn)行、編寫C語言程序的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03C語言基于graphics.h實(shí)現(xiàn)圣誕樹
這篇文章主要介紹了圣誕樹代碼,c語言編程,基于graphics.h實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-12-12Java C++ 算法leetcode828統(tǒng)計(jì)子串中唯一字符乘法原理
這篇文章主要為大家介紹了Java C++ 算法leetcode828統(tǒng)計(jì)子串中唯一字符乘法原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09