布局容器初始化时会触发move事件。或外部触发move事件
property int direction: Qt.application.layoutDirection
Row{
layoutDirection: root.direction
spacing: 10
id:mrow
//move是布局中的一个属性 在子元素移动时触发
move: Transition {
NumberAnimation{
duration: 400
properties: "x,y"
}
}
Repeater{
model: 5
Loader{
//加载commet元素 子元素可访问父元素自定义成员、属性
property int mvalue: index
sourceComponent: commet
}
}
}
Component {
id:commet
Rectangle{
color: Qt.rgba(0.8/(parent.mvalue+1),0.8/(parent.mvalue+1),0.8/(parent.mvalue+1),1.0)
width: 40
height: 40
Text{
text:parent.parent.mvalue+1
color: "white"
font.pixelSize: 18
anchors.centerIn: parent
}
}
}
//点击鼠标改变Row对齐方式 触发 move事件
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
if (root.direction == Qt.LeftToRight) {
root.direction = Qt.RightToLeft
} else {
root.direction = Qt.LeftToRight
}
}
}
}