原理
使用 Repeater来循环创建
如下代码,创建15个item
示例代码
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.4
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MouseArea {
id: theArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
if(mouse.button == Qt.RightButton) {
thumbnailMenu.popup()
}
}
}
Menu {
id: thumbnailMenu
Repeater {
id: recentFilesInstantiator
model: 15
delegate: MenuItem {
text: "test" +index
onTriggered:{
console.log(index)
}
}
}
}
}