QT qml---- loader使用方法

“简洁是智慧的灵魂,冗长是肤浅的藻饰”------------------《哈姆莱特》莎士比亚


Import Statement: import QtQuick 2.5

Loader is used to dynamically load QML components.

Loader can load a QML file (using the source property) or a Component object (using the sourceComponent property). It is useful for delaying the creation of a component until it is required: for example, when a component should be created on demand, or when a component should not be created unnecessarily for performance reasons.

The loaded object can be accessed using the item property.

If the source or sourceComponent changes, any previously instantiated items are destroyed. Setting source to an empty string or setting sourceComponent to undefined destroys the currently loaded object, freeing resources and leaving the Loader empty.

详细见QT文档。

小栗子:

import QtQuick 2.4
Item{

	Rectangle{//Rectangle内显示的内容由loader决定
	
            Loader{
                id : viewPanel
                anchors.fill: parent

            }

        }
		
	MouseArea {//当有信号来时,才load文件,生成实例
        anchors.fill: parent
        onClicked: {
                viewPanel.source = "selfDefined.qml" //自定义qml类型
                viewPanel.item.x= lineEdit1.x   //------The loaded object can be accessed using the item property
                viewPanel.item.y= lineEdit1.y+lineEdit1.height+2
                viewPanel.item.state="active"

                }
            }

}

转载于:https://www.cnblogs.com/butterflybay/p/10347981.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值