鼠标单击可选中当前项,头部呈绿色显示;按压当前项可进行拖拽更换列表项位置;点击数据可以进行编辑;

GitHub:八至

作者:狐狸家的鱼

这里是自己定义的model,有些字体和颜色都是使用的全局属性,

ListView{
id:thelist
property bool isClicked: false //初始化没有点击事件
anchors.fill: parent
clip:true
interactive: !isClicked
focus: true
flickableDirection: Flickable.VerticalFlick
boundsBehavior: Flickable.StopAtBounds
ScrollBar.vertical: ScrollBar {id:scrollBar;active: true;}
Keys.onUpPressed: scrollBar.decrease()
Keys.onDownPressed: scrollBar.increase()
move:Transition {
NumberAnimation{
properties: "x,y";
duration: 300
}
}
anchors {
left: parent.left; top: parent.top; right: parent.right;
margins: 2
}
spacing: 4
cacheBuffer: 50 //model: anAirModel
model: ListModel{
id:sstpModel;
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高 ALT-高度
status:"TAI"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//departureTime 起飞时间 离港时间
arrivalTime:"1423"// arrivalTime到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//takeOffRunway 起飞跑道
landingRunway:"xx"//landingRunway 降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"HANDOVER"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"CLR"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"OFF"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"DESCENT"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"DISENGAGE"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
ListElement{
air_iden:"CES5401"//呼号 航班号
type:"A319"//机型
el:"07056"//机场标高
status:"TAI"// 管制按钮 HANDOVER-移交 CLR-放行 TAI-滑行 OFF-起飞 DESCENT-降落 DISENGAGE-脱离
etd:"1215"//预计离港时间
eta:"1413"//预计到达时间
departureTime:"1215"//起飞时间 离港时间
arrivalTime:"1423"//到达时间 到港时间
ades:"ZSPD"//到达机场 目的地
takeOffRunway:"xx"//起飞跑道
landingRunway:"xx"//降落跑道
procedure:"xxx"//进离场程序 //tas:"K0860"//巡航速度 860km/h
//waypoint1:"TEBUN";//航路点
//assr:"6255"//应答机编码
//cvsm:"S0820"//对应高度层 82km
}
} delegate:Rectangle{
id:sstpDelegate
property int fromIndex:0
property int toIndex:0
width: parent.width
height: 80
MouseArea {
id:mousearea
anchors.fill: parent
onClicked: {
thelist.currentIndex = index
}
onPressed: {
thelist.currentIndex = index
sstpDelegate.fromIndex = index
thelist.isClicked = true //每项按钮点击就true }
onReleased: {
thelist.isClicked = false //每项按钮点击就false
console.log("fromIndex:",sstpDelegate.fromIndex,"toIndex:",sstpDelegate.toIndex)
}
onPositionChanged: {
var lastIndex = thelist.indexAt(mousearea.mouseX + sstpDelegate.x,mousearea.mouseY + sstpDelegate.y);
if ((lastIndex < 0) || (lastIndex > sstpModel.rowCount()))
return;
if (index !== lastIndex){
sstpModel.move(index, lastIndex, 1);
}
sstpDelegate.toIndex = lastIndex;
}
}
Row{
Rectangle{
id:curRect
width: 5
height: sstpDelegate.height
color: index===thelist.currentIndex ? Global.GlobalVar.sstpCurIndex : Global.GlobalVar.mainFontColor//选中颜色设置
}
Rectangle{//info
id:infoRect
width: sstpDelegate.width - controlRect.width - 5
height: sstpDelegate.height
RowLayout{
spacing: Global.GlobalVar.space*4
anchors.left: parent.left
anchors.leftMargin: Global.GlobalVar.space
ColumnLayout{
spacing: Global.GlobalVar.space
MyText{//航班呼号
text: air_iden
fontColor: b1
fontSize: xl
}
TextInput{//预计起飞时间
text: etd
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
TextInput{//起飞时间
text: departureTime
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
}
ColumnLayout{
spacing: Global.GlobalVar.space
MyText{//飞行机型
text: type
fontColor: b1
fontSize: m
}
TextInput{//预计到达时间
text: eta
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
TextInput{//到达时间
text: arrivalTime
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
}
ColumnLayout{
spacing: Global.GlobalVar.space*4
MyText{//机场标高
text: el
fontColor: b1
fontSize: m
}
TextInput{//目的机场
text: ades
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
}
ColumnLayout{
spacing: Global.GlobalVar.space*4
TextInput{//起飞跑道
text: takeOffRunway
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
}
TextInput{//进离场程序
text: procedure
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
onEditingFinished: { }
}
}
TextInput{//降落跑道
anchors.top: parent.top
text: takeOffRunway
color: Global.GlobalVar.mainFontColor
font.pointSize: 12
}
}
}
RecLine{id:recLine;direction:false}
Rectangle{
id:controlRect
width: 100
height: sstpDelegate.height
ColumnLayout{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
BorderButton{
implicitWidth: 80
implicitHeight: 30
borderbtnText: status
fontSize: 10
MouseArea{
anchors.fill: parent
}
}
MyText{
anchors.horizontalCenter: parent.horizontalCenter
font.family: "FontAwesome"
text: '\uf014'
fontSize: xl
MouseArea{
anchors.fill: parent
onClicked: an_del.open()
}
}
}
}
}
} IsDelDialog{id:an_del;x:SSTPWind.width/2;y:SSTPWind.height/2;}
Connections{
target: an_del.del_area;
onClicked:{
//anAirModel.remove(thelist.currentIndex)
sstpModel.remove(thelist.currentIndex)
an_del.close()
}
}
}

关于拖拽,参考https://blog.csdn.net/zhengtianzuo06/article/details/78631977,由于设置交互事件,会影响鼠标滚动和拖拽,所以进行了修改

interactive: !isClicked

这样就不会影响拖拽和鼠标滚动了。

QML学习笔记(七)— 实现可拖拽、编辑、选中的ListView的更多相关文章

  1. Bootstrap学习笔记之Nestable可拖拽树结构

    Nestable是基于Bootstrap的一个可拖拽的树结构表现插件. 下面粗略的介绍一下它的用法,只作为学习参考,如有不合适之处,请各位凑合看. 下图是我在现在系统中用到的Nestable,对系统模 ...

  2. OpenLayers学习笔记(六)— 拖拽叠加层overlayer

    是在官网例子基础上增加的拖拽功能 GitHub:八至 作者:狐狸家的鱼 本文链接:拖拽叠加层overlayer 全部代码 <!DOCTYPE html> <html> < ...

  3. OpenLayers学习笔记(五)— 拖拽Feature图层

    参考文档的例子可以知道如何拖动矢量图层feature GitHub: 八至 作者:狐狸家的鱼 本文链接:拖拽Feature图层 全部代码 <!DOCTYPE html> <html& ...

  4. (转)Qt Model/View 学习笔记 (七)——Delegate类

    Qt Model/View 学习笔记 (七) Delegate  类 概念 与MVC模式不同,model/view结构没有用于与用户交互的完全独立的组件.一般来讲, view负责把数据展示 给用户,也 ...

  5. Learning ROS for Robotics Programming Second Edition学习笔记(七) indigo PCL xtion pro live

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS forRobotics Pro ...

  6. QML学习笔记(六)- 简单计时器和定时器

    做一个简单的qml计时器和定时器,左键触发计时,右键触发定时 GitHub:八至 作者:狐狸家的鱼 本文链接:QML学习笔记(六)- 简单计时器和定时器 左键点击按钮,触发计时器,中键可以暂停计时,同 ...

  7. QML学习笔记(五)— 做一个简单的待做事项列表

    做一个简单的QML待做事项列表,能够动态添加和删除和编辑数据 GitHub:八至 作者:狐狸家的鱼 本文链接:QML学习笔记(五)— 做一个待做事项列表 主要用到QML:ListView 效果 全部代 ...

  8. Typescript 学习笔记七:泛型

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  9. python3.4学习笔记(七) 学习网站博客推荐

    python3.4学习笔记(七) 学习网站博客推荐 深入 Python 3http://sebug.net/paper/books/dive-into-python3/<深入 Python 3& ...

  10. Go语言学习笔记七: 函数

    Go语言学习笔记七: 函数 Go语言有函数还有方法,神奇不.这有点像python了. 函数定义 func function_name( [parameter list] ) [return_types ...

随机推荐

  1. __new__和__init__的区别

    __new__是一个静态方法,而__init__是一个实例方法. __new__方法会返回一个创建的实例,而__init__什么都不返回. 只有在__new__返回一个cls的实例时后面的__init ...

  2. 使用cmd命令删除文件夹下所有文件

    rmdir 删除整个目录 好比说我要删除 222 这个目录下的所有目录和档案,这语法就是: rmdir /s/q 222 其中: /s 是代表删除所有子目录跟其中的档案. /q 是不要它在删除档案或目 ...

  3. Programming好文解读系列(—)——代码整洁之道

    注:初入职场,作为一个程序员,要融入项目组的编程风格,渐渐地觉得系统地研究下如何写出整洁而高效的代码还是很有必要的.与在学校时写代码的情况不同,实现某个功能是不难的,需要下功夫的地方在于如何做一些防御 ...

  4. Python turtle绘制阴阳太极图代码解析

    本文详细分析如何使用Python turtle绘制阴阳太极图,先来分解这个图形,图片中有四种颜色,每条曲线上的箭头表示乌龟移动的方向,首先从中心画一个半圆(红线),以红线所示圆的直径作半径画一个校园, ...

  5. reshape

    reshape 编辑 reshape是一种函数,函数可以重新调整矩阵的行数.列数.维数.在matlab命令窗口中键入doc reshape或help reshape即可获得该函数的帮助信息. B = ...

  6. Error: File 'C:\somepath\bin\ARM\Release\App_1.1.218.0_scale-100.appx' not found.

    Hi Everyone, We are working on a fix for this issue as quickly as we can, but we have identified a w ...

  7. HTTP 错误 500.21 - Internal Server Error 处理程序“BlockViewHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler

    HTTP 错误 500.21 - Internal Server Error  处理程序“BlockViewHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler ...

  8. 18mysql3

    一.内外连接全连接,左右连接   █▓        通过两张表查找其对应的记录. 隐式 内连接 select * from a,b where a.列名 = b.列名   █▓        左连接 ...

  9. 简单探究Android平台下' if ' 语句条件判断耗时情况

    2017年6月13日 前言 前几日在改Bug时看到好多调试时用的日志语句都被一个日志开关控制着它的执行权.形如: if(Constants.LOG_TAG){ Log.d(TAG, "Ini ...

  10. 微信小程序——报错汇总

    tabBar.list[2].selectedIconPath 文件不存在 很明显是文件名错了,定义的my-acive,少写了个t,眼睛出问题了~ module "static/vant/c ...