Qt qml實(shí)現(xiàn)動(dòng)態(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:"請(qǐng)聯(lián)系管理員"}
ListElement{number:"111";note:"卡件";solution:"清除線體后重新啟動(dòng)"}
ListElement{number:"222";note:"等待處理";solution:"請(qǐng)聯(lián)系管理員"}
ListElement{number:"333";note:"等待處理";solution:"請(qǐng)聯(lián)系管理員"}
ListElement{number:"444";note:"等待處理";solution:"請(qǐng)聯(lián)系管理員"}
ListElement{number:"555";note:"等待處理";solution:"請(qǐng)聯(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:"請(qǐng)聯(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)原理
通過(guò)PathView實(shí)現(xiàn),通過(guò)路徑和縮放來(lái)實(shí)現(xiàn)動(dòng)態(tài)效果。
到此這篇關(guān)于Qt qml實(shí)現(xiàn)動(dòng)態(tài)輪播圖效果的文章就介紹到這了,更多相關(guān)Qt qml動(dòng)態(tài)輪播圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Qt6 QML實(shí)現(xiàn)DateTimePicker組件的示例代碼
- Qt?QML實(shí)現(xiàn)無(wú)邊框窗口的實(shí)例代碼
- QML與C++交互之創(chuàng)建自定義對(duì)象的實(shí)現(xiàn)
- Qt6+QML實(shí)現(xiàn)Windows屏幕錄制功能
- Qt?Qml實(shí)現(xiàn)毛玻璃效果
- 基于Qml實(shí)現(xiàn)水印工具
- QML與C++幾種交互方式
- Qt QML使用虛擬鍵盤(pán)的示例代碼
- C++與QML進(jìn)行數(shù)據(jù)交互的常見(jiàn)方法總結(jié)
- C++與QML交互的項(xiàng)目實(shí)踐
- Qt6 QML Flickable控件詳解
相關(guān)文章
C語(yǔ)言實(shí)現(xiàn)魔方比賽管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)魔方比賽管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
C語(yǔ)言中二級(jí)指針的應(yīng)用小結(jié)
二級(jí)指針是C語(yǔ)言中指向指針的指針,常用于在函數(shù)中修改指針的地址,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-11-11
QT自定義QTextEdit實(shí)現(xiàn)大數(shù)據(jù)的實(shí)時(shí)刷新顯示功能實(shí)例
TextEdit是我們常用的Qt控件,用來(lái)顯示文本信息,下面這篇文章主要給大家介紹了關(guān)于QT自定義QTextEdit實(shí)現(xiàn)大數(shù)據(jù)的實(shí)時(shí)刷新顯示功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05
C語(yǔ)言實(shí)現(xiàn)經(jīng)典掃雷小游戲的示例代碼
掃雷游戲是在一個(gè)指定的二維空間里,隨機(jī)布置雷,把不是雷的位置都找出來(lái),在你點(diǎn)一個(gè)位置的時(shí)候它會(huì)顯示它周圍全部雷的個(gè)數(shù),根據(jù)這個(gè)線索去找 ,會(huì)更容易贏。本文將用C語(yǔ)言實(shí)現(xiàn)這一經(jīng)典游戲,感興趣的可以嘗試一下2022-11-11
C++基于socket多線程實(shí)現(xiàn)網(wǎng)絡(luò)聊天室
這篇文章主要為大家詳細(xì)介紹了C++基于socket多線程實(shí)現(xiàn)網(wǎng)絡(luò)聊天室,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07
C語(yǔ)言詳解strcmp函數(shù)的分析及實(shí)現(xiàn)
strcmp函數(shù)語(yǔ)法為“int strcmp(char *str1,char *str2)”,其作用是比較字符串str1和str2是否相同,如果相同則返回0,如果不同,前者大于后者則返回1,否則返回-12022-05-05
詳解C++的String類的字符串分割實(shí)現(xiàn)
這篇文章主要介紹了詳解C++的String類的字符串分割實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-07-07

