Qt学习-ListView的拖拽
最近在学习Qt 里面的QML, 使用DropArea和MouseArea实现了ListView的拖拽.
想起了当年用Delphi, 差不多一样的东西, 不过那是2000了. Delphi也是不争气啊, 多好的IDE, 硬生生发展不起来.....
代码可以在 https://github.com/cnscud/learn/tree/master/qt/dragdroplistview 找到
/**
samples changed from Qt tutorial "dynamicview3"
*/
import QtQuick 2.0
import QtQml.Models 2.1
Rectangle {
id: root
width: 300; height: 400
Component {
id: dragDelegate
MouseArea {
id: dragArea
anchors { left: parent.left; right: parent.right }
height: content.height
// Disable smoothed so that the Item pixel
// from where we started the drag remains under the mouse cursor
drag.smoothed: false
drag.target: content
drag.axis: Drag.YAxis
Rectangle {
id: content
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
width: dragArea.width; height: column.implicitHeight + 4
border.width: 1
border.color: "lightsteelblue"
color: dragArea.drag.active ? "lightsteelblue" : "white"
Behavior on color { ColorAnimation { duration: 100 } }
radius: 2
Drag.active: dragArea.drag.active
Drag.source: dragArea
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
states: State {
when: content.Drag.active
ParentChange { target: content; parent: root }
AnchorChanges {
target: content
anchors { horizontalCenter: undefined; verticalCenter: undefined }
}
}
Column {
id: column
anchors { fill: parent; margins: 2 }
Text { text: 'Name: ' + name }
}
}
DropArea {
anchors { fill: parent; margins: 10 }
onEntered: {
visualModel.items.move(
drag.source.DelegateModel.itemsIndex,
dragArea.DelegateModel.itemsIndex)
}
}
}
}
DelegateModel {
id: visualModel
model: PetsModel {}
delegate: dragDelegate
}
ListView {
id: view
anchors { fill: parent; margins: 2 }
model: visualModel
spacing: 4
cacheBuffer: 50
moveDisplaced: Transition {
NumberAnimation { properties: "x,y"; duration: 200 }
}
}
}
用的PetModels如下:
import QtQuick 2.0
ListModel {
ListElement {
name: "Polly"
type: "Parrot"
age: 12
size: "Small"
}
ListElement {
name: "Penny"
type: "Turtle"
age: 4
size: "Small"
}
ListElement {
name: "Warren"
type: "Rabbit"
age: 2
size: "Small"
}
ListElement {
name: "Spot"
type: "Dog"
age: 9
size: "Medium"
}
ListElement {
name: "Schrödinger"
type: "Cat"
age: 2
size: "Medium"
}
ListElement {
name: "Joey"
type: "Kangaroo"
age: 1
size: "Medium"
}
ListElement {
name: "Kimba"
type: "Bunny"
age: 65
size: "Large"
}
ListElement {
name: "Rover"
type: "Dog"
age: 5
size: "Large"
}
ListElement {
name: "Tiny"
type: "Elephant"
age: 15
size: "Large"
}
}
Qt学习-ListView的拖拽的更多相关文章
- ListView列表拖拽排序
ListView列表拖拽排序能够參考Android源代码下的Music播放列表,他是能够拖拽的,源代码在[packages/apps/Music下的TouchInterceptor.java下]. 首 ...
- QT 标题栏隐藏可拖拽
这个也是我网上找到了 为了方便,记录一下 void mousePressEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e); void ...
- Android学习系列(11)--App列表之拖拽ListView(下)
接着上篇Android学习系列(10)--App列表之拖拽ListView(上)我们继续实现ListView的拖拽效果. 7.重写onTouchEvent()方法. 在这个方法中我们主要是处理 ...
- Android学习系列--App列表之拖拽ListView(下)
接着上篇Android学习系列(10)--App列表之拖拽ListView(上)我们继续实现ListView的拖拽效果. 7.重写onTouchEvent()方法. 在这个方法中我们主要是处理 ...
- QT笔记之自定义窗口拖拽移动
1.QT自定义标题栏,拖拽标题栏移动窗口(只能拖拽标题,其他位置无法拖拽) 方法一: 转载:http://blog.sina.com.cn/s/blog_4ba5b45e0102e83h.html . ...
- Qt图形视图体系结构示例解析(视图、拖拽、动画)
本博的示例来自与QT Example:C:\Qt\Qt5.9.3\Examples\Qt-5.9.3\widgets\graphicsview\dragdroprobot 将通过分析示例完成主要功能: ...
- QT学习之windows下安装配置PyQt5
windows下安装配置PyQt5 目录 为什么要学习QT 命令行安装PyQt5以及PyQt5-tools 配置QtDesigner.PyUIC及PyRcc 为什么要学习QT python下与界面开发 ...
- Android 可拖拽的GridView效果实现, 长按可拖拽和item实时交换
转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17718579),请尊重他人的辛勤劳动成果,谢谢! 在And ...
- QML之窗口(无边框、透明及拖拽)
1.无边框 Qt Quick 2.0 中 QQuickView代替了1.0中的QDeclarativeView. 无边框窗口代码如下: QQuickView viwer; //QQuickView继承 ...
随机推荐
- SpringCloud Alibaba实战(8:使用OpenFeign服务调用)
源码地址:https://gitee.com/fighter3/eshop-project.git 持续更新中-- 在上一个章节,我们已经成功地将服务注册到了Nacos注册中心,实现了服务注册和服务发 ...
- 【spring源码系列】之【Bean的生命周期】
为源码付出的每一分努力都不会白费. 1. Bean的实例化概述 前一篇分析了BeanDefinition的封装过程,最终将beanName与BeanDefinition以一对一映射关系放到beanDe ...
- 20204107 孙嘉临《Python程序设计》实验一报告
课程:<python程序设计> 班级:2041 姓名:孙嘉临 学号:20204107 实验教师:王志强 实验日期:2021年4月12日 必修/选修:公选课 ##一.实验内容 1.熟悉Pyt ...
- 3、SpringBoot整合之SpringBoot整合JDBC
SpringBoot整合JDBC 一.创建SpringBoot项目 选择Spring Web.JDBC API.MySQL Driver 二.在pom配置文件中修改JDBC版本,导入lombok &l ...
- C# 实现复制Excel内容到DataGridview中
业务要求:复制:将Excel内容复制到datagridview中 最终效果:复制Excel内容,点击datagridview中的某个单元格,顺着这个单元格自动填充自动增加行.偷懒了,没写填充在选择哪些 ...
- Docker:如何修改Docker0网桥的默认网段
1. 背景 Docker 服务启动后默认会创建一个 docker0 网桥(其上有一个 docker0 内部接口),它在内核层连通了其他的物理或虚拟网卡,这就将所有容器和本地主机都放到同一个物理网络. ...
- 第八章 - JUC
J.U.C AQS 原理 全称是 AbstractQueuedSynchronizer,是阻塞式锁和相关的同步器工具的框架 特点: 用 state 属性来表示资源的状态(分独占模式和共享模式),子类需 ...
- Linux查找占用的端口,并杀死进程
我要使用4040端口,但是被其他的程序占用了 1. 查找占用的程序 netstat -apn | grep 4040 最后一项显示的是pid和对应的名称 2. 杀掉对应的进程,彻底杀死进程 kill ...
- 从S3中拷贝或同步文件
p.p1 { margin: 0; font: 16px "Helvetica Neue"; color: rgba(53, 53, 53, 1) } p.p2 { margin: ...
- 输出数组中出现次数最多且值最大的数字----python
class Solution(): #求最多的数 def find_max(self,list): num = 0 for i in list: print(i) if list.count(i) & ...