File tree Expand file tree Collapse file tree 7 files changed +169
-0
lines changed Expand file tree Collapse file tree 7 files changed +169
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ <RCC>
2
+ <qresource prefix="/">
3
+ <file>main.qml</file>
4
+ </qresource>
5
+ </RCC>
Original file line number Diff line number Diff line change @@ -38,3 +38,4 @@ SUBDIRS += QmlKey
38
38
SUBDIRS += QmlLoader
39
39
SUBDIRS += QmlInvertedImage
40
40
SUBDIRS += QmlFontAwesome
41
+ SUBDIRS += QmlListSlidDelete
Original file line number Diff line number Diff line change @@ -173,3 +173,7 @@ QmlFontAwesome: Qml使用FontAwesome
173
173
![ ] ( https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFontAwesome/show.jpg?raw=true )
174
174
175
175
176
+ QmlListSlidDelete: Qml滑动删除
177
+
178
+ ![ ] ( https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlListSlidDelete/show.gif?raw=true )
179
+
You can’t perform that action at this time.
0 commit comments