RecipeSphase是一个组件而不是一个项目,一个组件类似于一个类,一个项目类似于一个对象,所以其思想是动态地创建项目。例如,我将考虑recipesphase是以下组件:
接收相位.qml
import QtQuick 2.0
Rectangle {
width: 100
height: 100
color: "red"
}
然后,每次按下鼠标指针,都会创建一个随机颜色的RecipeSphase:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.4
Window {
visible: true
width: 640
height: 480
title: qsTr("Example")
property int curIndexWitouthZero: 0
SwipeView {
id: viewSwipe
width: parent.width
height: parent.height * 0.70
currentIndex: 0
Component.onCompleted: {
curIndexWitouthZero = viewSwipe.currentIndex
curIndexWitouthZero += 1
addPage(createPage())
}
onCurrentIndexChanged: {
curIndexWitouthZero = viewSwipe.currentIndex
curIndexWitouthZero += 1
}
function addPage(page) {
console.log("funzione addPage()")
addItem(page)
page.visible = true
}
function createPage(){
var component = Qt.createComponent("RecipesPhase.qml");
var page = component.createObject(viewSwipe,
{"color": Qt.rgba(Math.random(), Math.random(), Math.random(), Math.random())}
);
return page
}
}
PageIndicator {
id: indicator
interactive: true
count: viewSwipe.count
currentIndex: viewSwipe.currentIndex
onCurrentIndexChanged: viewSwipe.currentIndex = currentIndex
anchors.top: viewSwipe.bottom
anchors.topMargin: parent.height * 0.05
anchors.horizontalCenter: parent.horizontalCenter
}
MouseArea{
anchors.top: indicator.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
onClicked: viewSwipe.addPage(viewSwipe.createPage())
}
}