Qt qml GritView使用
import QtQuick 2.15
Item {
ListModel{
id: nameModel
ListElement{ file: "qrc:/image/image/1.png"; name: "image1"}
ListElement{ file: "qrc:/image/image/1.png"; name: "image2"}
ListElement{ file: "qrc:/image/image/1.png"; name: "image3"}
ListElement{ file: "qrc:/image/image/1.png"; name: "image4"}
}
Component{
id: nameDelegate
Column{
Image{
id: delegateImage
anchors.horizontalCenter: delegateText.horizontalCenter
source: model.file
width: 64
height: 64
smooth: true
}
Text{
id: delegateText
text: model.name
font.pixelSize: 24
}
}
}
GridView{
anchors.fill: parent
anchors.margins: 10
model: nameModel
delegate: nameDelegate
clip: true
}
}
效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b8722fc570f9b5425df068766cd4ae3b.png#pic_center)