QML中的AnchorChanges锚布局改变元素

来源:互联网 发布:知乎布鲁塞尔自由大学 编辑:程序博客网 时间:2024/06/08 13:11

AnchorChanges用来改变锚布局,其实你完全可以用属性来进行,这个元素不过是对属性的细化而已。

一个简单的单击鼠标改变锚布局属性的例子:


import QtQuick 2.4import QtQuick.Window 2.2Window {    id:rootItem    visible: true    width: 400    height: 500    MouseArea {        anchors.fill: parent        onClicked: {                 redRect.state="clicked"//QML的调试真的很烂,这里我开始多写了一个等号,不能执行,但是不报错        }    }    Rectangle{        id:blueRect        x:8        y:8        width: 100        height: 100        color: "blue"    }    Rectangle{        id:redRect        width: 100        height: 100        color: "red"        anchors.left: blueRect.right        anchors.top: blueRect.top        states: [            State {                name: "default"                AnchorChanges {                    target: blueRect                    anchors.left: blueRect.right                    anchors.top: blueRect.top                }            },            State {                name: "clicked"                AnchorChanges {                    target: redRect                    anchors.left: blueRect.left                    anchors.top: blueRect.bottom                }            }        ]    }}


0 0
原创粉丝点击