QtQuick动态创建组件
来源:互联网 发布:在数据库中存储的是 编辑:程序博客网 时间:2024/04/27 05:45
1.Qt.createComponent 创建组件对象 createObject指定父元素
**Ani.QmlAnimatedImage { id: animation; source: "qrc:/T.gif" width: 40 height: 40}
**Text.QmlText{ width: 40 height: 40 text: "Hello" verticalAlignment: Text.AlignBottom}
**main.Qmlimport QtQuick 2.7import QtQuick.Controls 2.0import QtQuick.Layouts 1.0ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") property var ff: 0 SwipeView { id: swipeView anchors.fill: parent currentIndex: tabBar.currentIndex Page{ Flow{ id:grid spacing: 0 width: swipeView.width height: swipeView.height Button{ text: "hello" onClicked: { ff++; if(ff%2==0) { loadButton() }else{ loadImg() } } function loadButton() { var obj = Qt.createComponent("Text.qml"); if (obj.status == Component.Ready) { var txt = obj.createObject(grid); } } function loadImg() { var obj = Qt.createComponent("Ani.qml"); if (obj .status == Component.Ready) { var img = obj .createObject(grid); } } } Button{ text: "hello" } Button{ text: "hello" } Button{ text: "hello" } Button{ text: "hello" } } MouseArea{ onClicked: { parent.loadButton() } } } } footer: TabBar { id: tabBar currentIndex: swipeView.currentIndex TabButton { text: qsTr("First") } TabButton { text: qsTr("Second") } }}
简化:Gobal.js
**Gobal.js.pragma libraryvar Component_Ready =1;function createxx(file,parent){ var component = Qt.createComponent(file); if (component.status == Component_Ready) { var button = component.createObject(parent); return button; } return null;}***********import "Gobal.js" as Helper function loadButton() { var obj = Helper.createxx("Button.qml",grid); if(obj!=null) { obj.color ="red" } }
2.使用createQmlObject创建,不建议使用
0 0
- QtQuick动态创建组件
- 动态创建一个组件
- 动态创建tidhttp组件
- 动态创建vb组件
- 动态创建组件
- Android动态创建组件
- qtquick创建UI界面文件
- QtQuick学习笔记(三)组件
- VFP开发动态创建组件
- QML如何创建动态组件
- 用fragment创建动态组件
- Angular4动态创建组件--根据组件名称动态创建出来组件
- Angular4动态创建组件--根据组件名称动态创建出来组件
- BCB中实现动态创建组件
- 在Delphi中动态创建ActiveX组件
- BCB 动态创建组件的事件响应
- FLEX如何动态创建DataGrid组件详解
- BCB 动态创建组件的事件响应
- 跳转动画设置
- zookeeper 集群配置
- 如何从AD中彻底删除Skype For Business(下篇)
- android内容提供者ContentProvider,UriMatcher和内容观察者ContentObserver常见使用
- 九度OJ 1020 最小长方形
- QtQuick动态创建组件
- 线程(一)线程安全和不安全
- 斜率优化
- 【c++程序】字符串反转
- 2016~六月英语·活动·成长
- Android 自定义线程池
- 练习四1005
- XListView的使用
- Rxjava四步走到高级掌握