QML学习03(Component、Loader)
QML学习
- 1、前言
- 2、Component
- 3、Loader
- 3.1 加载图片
- 4、总结
1、前言
记录一下QML学习的过程,方便自己日后回顾,也可以给有需要的人提供帮助。 |
2、Component
Component.onCompleted: {console.log("onCompleted",width,height,color)
}Component.onDestruction: {console.log("onDestruction",width,height,color)
}
3、Loader
Component{id: comRectangle{id:rectwidth: 200height: 100color: "black"Component.onCompleted: {console.log("onCompleted",width,height,color)}Component.onDestruction: {console.log("onDestruction",width,height,color)}}}//加载控件Loader{id:loadersourceComponent: comonStatusChanged: {console.log("status",status)}}Button{width:50height:50x:200onClicked: {//修改loader加载组件loader.item.width = 50loader.item.height = 50loader.item.color = "red"
// loader.sourceComponent = null}}
3.1 加载图片
//加载图片Component{id:comAnimatedImage{id:img//source: "/nezha.png" //图片source: "/dog.gif" //gif图//speed: 10 //速度}}//加载控件Loader{id:loader//异步加载asynchronous: truesourceComponent: comonStatusChanged: {console.log("status",status)}}Button{width:50height:50x:200onClicked: {//修改loader加载组件loader.item.paused = !loader.item.paused //暂停动画
// loader.item.width = 50
// loader.item.height = 50
// loader.item.color = "red"
// loader.sourceComponent = null}}
4、总结
以上就是QML学习的一些基础知识了,如若发现错误,欢迎大家指正,有问题的欢迎评论区留言或者私信。最后,如果大家觉得有所帮助,可以点一下赞,谢谢大家!祝大家天天开心,顺遂无虞!