Skip to content

Commit c1fa6de

Browse files
committed
Add QmlListSlidDelete
1 parent f87ac13 commit c1fa6de

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlListSlidDelete/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
if (engine.rootObjects().isEmpty())
19+
return -1;
20+
21+
return app.exec();
22+
}

QmlListSlidDelete/main.qml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
11+
ApplicationWindow {
12+
visible: true
13+
width: 400
14+
height: 300
15+
title: qsTr("Qml滑动删除")
16+
17+
ListModel {
18+
id: listModel
19+
20+
ListElement {
21+
text: qsTr("111222333随便的一些内容")
22+
}
23+
ListElement {
24+
text: qsTr("AAABBBCCC随便的一些内容")
25+
}
26+
ListElement {
27+
text: qsTr("DDDEEEFFF随便的一些内容")
28+
}
29+
ListElement {
30+
text: qsTr("GGGHHHIII随便的一些内容")
31+
}
32+
ListElement {
33+
text: qsTr("JJJKKKLLL随便的一些内容")
34+
}
35+
}
36+
37+
ListView{
38+
id: listview
39+
width: parent.width
40+
height: parent.height
41+
anchors.fill: parent
42+
model: listModel
43+
delegate: listDelegate
44+
}
45+
46+
Component{
47+
id: listDelegate
48+
Rectangle{
49+
id: listItem
50+
width: parent.width
51+
height: 30
52+
53+
Text {
54+
id: text
55+
font.family: "microsoft yahei"
56+
font.pointSize: 12
57+
height: parent.height
58+
width: parent.width - delBtn.width
59+
text: model.text
60+
color: "green"
61+
verticalAlignment: Text.AlignVCenter
62+
MouseArea{
63+
property point clickPos: "0,0"
64+
65+
anchors.fill: parent
66+
onPressed: {
67+
clickPos = Qt.point(mouse.x,mouse.y);
68+
}
69+
onReleased: {
70+
var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
71+
console.debug("delta.x: " + delta.x);
72+
if ((delta.x < 0) && (aBtnShow.running === false) && (delBtn.width == 0)){
73+
aBtnShow.start();
74+
}else if (aBtnHide.running === false && (delBtn.width > 0)){
75+
aBtnHide.start();
76+
}
77+
}
78+
}
79+
}
80+
Rectangle{
81+
color: "#AAAAAA"
82+
height: 1
83+
width: parent.width
84+
anchors.bottom: parent.bottom
85+
}
86+
Rectangle{
87+
id: delBtn
88+
height: parent.height
89+
width: 0
90+
color: "#EE4040"
91+
anchors.right: parent.right
92+
Text {
93+
font.family: "microsoft yahei"
94+
font.pointSize: 12
95+
anchors.centerIn: parent
96+
text: qsTr("删除")
97+
color: "#ffffff"
98+
}
99+
MouseArea{
100+
anchors.fill: parent
101+
onClicked: {
102+
listview.model.remove(index);
103+
}
104+
}
105+
}
106+
PropertyAnimation{
107+
id: aBtnShow
108+
target: delBtn
109+
property: "width"
110+
duration: 100
111+
from: 0
112+
to: 60
113+
}
114+
PropertyAnimation{
115+
id: aBtnHide
116+
target: delBtn
117+
property: "width"
118+
duration: 100
119+
from: 60
120+
to: 0
121+
}
122+
}
123+
}
124+
}

QmlListSlidDelete/qml.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
</qresource>
5+
</RCC>

QmlListSlidDelete/show.gif

95.4 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ SUBDIRS += QmlKey
3838
SUBDIRS += QmlLoader
3939
SUBDIRS += QmlInvertedImage
4040
SUBDIRS += QmlFontAwesome
41+
SUBDIRS += QmlListSlidDelete

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ QmlFontAwesome: Qml使用FontAwesome
173173
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFontAwesome/show.jpg?raw=true)
174174

175175

176+
QmlListSlidDelete: Qml滑动删除
177+
178+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlListSlidDelete/show.gif?raw=true)
179+

0 commit comments

Comments
 (0)