Qt 示例学习--1. 1 qml实现list
来源:互联网 发布:coc法师塔升级数据 编辑:程序博客网 时间:2024/05/01 23:19
开头
之前学习了Qt的第一个示例,其中使用到了quick,基本理解思路,但并不是很理解qml的使用,遂仿照例子自己写了个list
实作
- 新建Qt Quick Application
- 实作main.qml(并添加图片资源,图片均添加的是Qt例子中的图片)
分析main.qml:
import QtQuick 2.3import QtQuick.Window 2.2import QtQuick.Controls 1.4import QtQuick.Controls.Styles 1.4import QtQuick.Layouts 1.2Window { visible: true width: 400 height: 640 ListModel { id: listModel } MouseArea { anchors.fill: parent onClicked: { //Qt.quit(); } } ListView { width: parent.width anchors.top: parent.top anchors.bottom: foot.top model: listModel Component.onCompleted: { listModel.append({"name": "a", "number": "111"}) listModel.append({"name": "b", "number": "111"}) } delegate: listDelegate add: Transition { NumberAnimation { properties: "y"; from: root.height; duration: 250 } } removeDisplaced: Transition { NumberAnimation { properties: "y"; duration: 150 } } remove: Transition { NumberAnimation { property: "opacity"; to: 0; duration: 150 } } } Row { id: foot anchors.bottom: parent.bottom width: parent.width height: 50 Button { text: "add" height: parent.height width: parent.width / 2 onClicked: { var name = "%1" listModel.append({"name": name.arg(listModel.count), "number": "111"}) } } Button { text: "remove" height: parent.height width: parent.width / 2 onClicked: { listModel.remove(0, 1) } } } Component { id: listDelegate BorderImage { width: parent.width; height: 70 source: mouse.pressed ? "qrc:/src/delegate_pressed.png" : "qrc:/src/delegate.png" MouseArea { id: mouse anchors.fill: parent hoverEnabled: true } CheckBox { x: 20 anchors.verticalCenter: parent.verticalCenter text: qsTr("") style: CheckBoxStyle { indicator: Image { source: control.checked ? "qrc:/src/checkbox_checked.png" : "qrc:/src/checkbox.png" } } } Text { width: parent.width ; height: 70 text: "name : " + name + " number : " + number font.pointSize: 13 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter } } }}
主体为ListView和底部的Row 布局(Row布局中仅添加两个按钮用于添加删除list项目)
为了在ListView中展示内容指定了ListModel和自定义的Delegate用于控制展示。
通过代码可以看到,这里Delegate控制较c++代码进行设置要方便很多~~
最后上效果图:
0 0
- Qt 示例学习--1. 1 qml实现list
- Qt 示例学习--1. enginio qml todos
- QML for QT 1
- Qt for Android QML实现缩放、拖拽、长按效果简单示例
- QT QML 信号 处理 1
- Qt、Opencv、QML实现摄像头简单对比
- Qt/QML 窗口阴影边框实现
- Qt/QML窗口阴影边框实现
- Qt 5学习(二)QML
- Qt界面之QML优秀学习网站
- Qt用QML调用Android的摄像头简单示例
- Qt QML
- QML学习(1)
- Qt学习: QPixmap实现的截屏程序代码示例
- 用QML和Qt C++实现翻页效果的研究(1)
- qml 数组操作(qt quick1.1)
- 在QML中鼠标单击特殊效果实现示例
- 学习:QML 实现瀑布流(他人代码)
- Qt5.4以上版本使用MySQL数据库(避免各种坑)
- 使用Cornerstone同步后,点击运行,提示“couldn't load project”,以及解决冲突
- Linux chgrp --修改文件或目录的所属群组
- png数据格式包括长度_超白痴向
- 自定义tabBar如何移除系统自带的TabBarItemButton
- Qt 示例学习--1. 1 qml实现list
- android Handler原理
- Linux chkconfig --查询/修改系统服务的运行级别
- Qt标准对话框之QMessageBox
- javax.net.ssl.SSLProtocolException: handshakealert: unrecognized_name
- 在OpenStack下部署Hadoop时启动不了NameNode问题的解决
- Win7系统怎么移动、删除pagefile.sys(页面)文件
- 卡片式UI的总结 android
- JS中函数参数的传递