【发布时间】:2017-05-04 17:47:17
【问题描述】:
我正面临 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
}
}
【问题讨论】: