使用Qml创建各种list(二)创建一个简单的动态列表
2011-03-27 12:46
579 查看
这里简单实现一个具有动态添加和清除属性的列表。
实现的主要方法使用model的append和clear属性。
PS有个小记录,就是listmodel中的元素如果不为空的话,默认是在屏幕直接显示的,其属性和属性名称并不需要预先定义
实现的主要方法使用model的append和clear属性。
PS有个小记录,就是listmodel中的元素如果不为空的话,默认是在屏幕直接显示的,其属性和属性名称并不需要预先定义
import Qt 4.7 import "content" Rectangle { id: container width: 500; height: 400 color: "#343434" ListModel { id: recipesModel } Component { id: recipeDelegate Item { id: recipe property real detailsOpacity : 0 width: listView.width height: 70 // A simple rounded rectangle for the background Rectangle { id: background x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2 color: "ivory" border.color: "orange" radius: 5 } Row { id: topLayout x: 10; y: 10; height: recipeImage.height; width: parent.width spacing: 10 Image { id: recipeImage width: 50; height: 50 source: picture } Column { width: background.width - recipeImage.width - 20; height: recipeImage.height spacing: 5 Text { text: title font.bold: true; font.pointSize: 16 } }// Column }// Row }// Item }// Component ListView { id: listView clip: true anchors.fill: parent model: recipesModel delegate: recipeDelegate } Row { anchors { left: parent.left; bottom: parent.bottom; margins: 20 } spacing: 10 TextButton { text: "Add an item" onClicked: { var pic = "http://pic.wenwen.soso.com/p/20090619/20090619144752-2127281241.jpg" recipesModel.append({ //注意这个“,” 如果没有的话运行会报,Unable to assign [undefined] to QUrl source 错误 title: "Vegetable Soup", picture: pic }) } } TextButton { text: "Remove all items" onClicked: recipesModel.clear() } } }
相关文章推荐
- 使用Qml创建各种list(一)---创建一个简单图片列表
- 使用GTK与Glade创建一个简单的列表的图形详解
- C#使用泛型数组简单实现一个列表List
- 创建一个简单的HTTP服务(自动查找未使用的端口)
- disruptor demo(一) 使用原生API创建一个简单的生产者和消费者
- 一个简单的支持排序的双栏列表(使用jquery)
- [Andriod官方训练教程]使用Fragment创建一个动态的UI之使用Support Library
- 使用ListAcyivity实现动态菜单列表
- 使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之二
- IronPython for ASP.NET:使用IronPython创建一个简单的Web页面
- MyEclipse通过TomCat创建一个简单的Web后台供Android使用
- CoreText 使用教程:以创建一个简单的杂志应用为例
- [使用心得]maven2之m2eclipse使用手册之六使用Maven2插件创建一个简单的SSH2项目之glassfish篇(二)
- 使用Cocos Studio创建一个简单的工程
- <c:foreach>解决遍历一个list创建多行多列列表的问题
- 使用eclipse创建JPA-->:附带一个简单的例子
- 使用jQuery动态创建一个表格(根据用户输入的内容添加一行数据,并且能逐行删除)
- 使用IntelliJ IDEA 创建一个简单的Hello Word
- 使用Spring来创建一个简单的工作流引擎
- 使用idea搭建一个简单的SSM框架:(1)使用idea创建maven项目