QML类型说明-AnchorChanges

本文详细介绍了如何使用AnchorChanges和PropertyChanges在QtQuick中修改项目锚和边缘,通过实例展示了如何改变项目锚的顶部和底部,以及如何通过PropertyChanges改变项目顶部和底部的边缘。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AnchorChanges

ImportStatement:   import QtQuick2.2

 

Properties

anchors

anchors.left : AnchorLine

anchors.right : AnchorLine

anchors.horizontalCenter : AnchorLine

anchors.top : AnchorLine

anchors.bottom : AnchorLine

anchors.verticalCenter : AnchorLine

anchors.baseline : AnchorLine

target : Item

 

DetailedDescription

AnchorChanges用来修改项目状态中的锚。它不能用来修改项目的边缘。项目的边缘可用PropertyChanges修改。

下面的例子中,我们用AnchorChanges改变了项目锚的顶部和底部,用PropertyChanges改变了项目顶部和底部的边缘。

import QtQuick 2.0

 

Rectangle {

id: window

width: 120; height: 120

color: "black"

Rectangle { id: myRect; width: 50; height: 50;color: "red" }

states: State {

name: "reanchored"

AnchorChanges {

target: myRect

anchors.top: window.top

anchors.bottom: window.bottom

}

PropertyChanges {

target: myRect

anchors.topMargin: 10

anchors.bottomMargin: 10

}

}

MouseArea { anchors.fill: parent; onClicked:window.state = "reanchored" }

}

 

QML类型说明-AnchorChanges

AnchorChanges能用AnchorAnimation动画化。

//animate our anchor changes

Transition {

AnchorAnimation {}

}

改变锚的边缘可以用NumberAnimation动画化。

更多关于锚的信息,看Anchor Layouts。

 

PropertyDocumentation

anchors group

anchors.left : AnchorLine

anchors.right : AnchorLine

anchors.horizontalCenter : AnchorLine

anchors.top : AnchorLine

anchors.bottom : AnchorLine

anchors.verticalCenter : AnchorLine

anchors.baseline : AnchorLine

这些属性表示了各自实例的锚。我们可以分配未定义来重置锚。

AnchorChanges {

target: myItem

anchors.left:undefined         //移除myItem的左锚。

anchors.right: otherItem.right

}

 

target : Item

这个属性表示了锚变化用在那个实例上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值