我正面臨着Pathview的問題。我需要更改路徑屬性以重新組織子項目,但是當我這樣做時,會導致所有創建的元素(由模型指定)被銷燬並重新創建。QML正在改變Pathview的路徑無需重新加載內容
有沒有辦法做到這一點,而無需重新加載內容,或者'掩蓋'眨眼效果?
例子:
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Window {
visible: true
width: 640
height: 480
title: qsTr("PathView path test")
Path {
id: path1
startX: 100; startY: 100
PathLine{ x: 300; y: 100 }
}
Path {
id: path2
startX: 100; startY: 100
PathLine{ x: 100; y: 300 }
}
ListModel {
id: pvModel
ListElement{ name: "rectangle" }
ListElement{ name: "rectangle" }
ListElement{ name: "rectangle" }
}
Component {
id: pvDelegate
Rectangle {
width: 50
height: 50
color: "red"
border.width: 1
Component.onCompleted: console.log("Rectangle created")
Component.onDestruction: console.log("Rectangle deleted")
}
}
property bool currentPath;
PathView {
anchors.fill: parent
model: pvModel
delegate: pvDelegate
path: (currentPath ? path1 : path2)
}
Button {
width: 100
height: 40
text: "Switch path"
onClicked: currentPath = !currentPath
}
}
它的工作,但現在,我無法訪問從我的新委託PathAttribute定義的附加屬性,我怎麼能做到這一點? – Macias
編輯:現在一切工作正常,我不得不將所有附加屬性定義爲默認值在每個路徑中,因爲不重裝委託綁定不起作用。感謝您的幫助:) – Macias