QML中的AnchorChanges锚布局改变元素
2016-03-18 16:44
459 查看
AnchorChanges用来改变锚布局,其实你完全可以用属性来进行,这个元素不过是对属性的细化而已。
一个简单的单击鼠标改变锚布局属性的例子:
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
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
}
}
]
}
}
![](https://img-blog.csdn.net/20160318164346222?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
一个简单的单击鼠标改变锚布局属性的例子:
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
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
}
}
]
}
}
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt 5.6更新至RC版,最终版本近在咫尺
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)