Component
组件,结合已有元素封装自己需要的控件。
progress : realstatus : enumerationurl : url
completed() //组件构建完成destruction() //销毁组件
object createObject(QtObject parent, object properties)string errorString()object incubateObject(Item parent, object properties, enumeration mode)
Loader
动态加载组件,继承自Item,通过Loader加载组件后如果需要对组件属性进行修改,可通过item加载组件中元素,然后可对其属性进行修改。
active : boolasynchronous : boolitem : object //Loader加载的顶级元素progress : realsource : urlsourceComponent : Componentstatus : enumeration
loaded()
object setSource(url source, object properties)
实操:
Component{id:comRectangle{id: rectwidth: 100height: 100color: "lightblue"Component.onCompleted: {console.log("onCompleted width: ", width, "height: ", height)}Component.onDestruction: {// console.log("onDestruction width: ", width, "height: ", height)}}}Loader{id: loader// source: "/2.jpg" //不可加载图片,status会报error// source: "rectangle.qml" //可加载qml文件asynchronous: true //异步加载,status从loading到readysourceComponent: comonStatusChanged: {console.log("status:", status)}}Button{width: 50height: 50x: loader.item.widthonPressed: { //按下的时候不会加载的组件loader.sourceComponent = null}onReleased: { //松开的时候会重新加载组件loader.sourceComponent = comloader.item.width = 80loader.item.height = 80loader.item.color = "blue"}}
Component{id: com// Image {// id: img// source: "/2.jpg"//// source: "/th.gif" //不可加载动画// width:200// height:200// }AnimatedImage { //动图id: img// source: "/2.jpg"source: "/th.gif" //加载动画与静态图speed: 2 //修改动图播放速度width:200height:200}}Loader{id: loader// source: "/2.jpg" //不可加载图片,status会报error// source: "rectangle.qml" //可加载qml文件asynchronous: true //异步加载,status从loading到readysourceComponent: comonStatusChanged: {console.log("status:", status)}}Button{width: 50height: 50x: loader.item.widthonPressed: { //暂停动图播放loader.item.paused = true}onReleased: { //开始动图播放loader.item.paused = false}}
