Skip to content

Commit

Permalink
Add QmlListSlidDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengtianzuo committed Nov 11, 2017
1 parent f87ac13 commit c1fa6de
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 0 deletions.
13 changes: 13 additions & 0 deletions QmlListSlidDelete/QmlListSlidDelete.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#-------------------------------------------------
#
# Copyright (C) 2003-2103 CamelSoft Corporation
#
#-------------------------------------------------

QT += qml quick

CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc
22 changes: 22 additions & 0 deletions QmlListSlidDelete/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
*@file main.cpp
*@brief 程序主文件
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;

return app.exec();
}
124 changes: 124 additions & 0 deletions QmlListSlidDelete/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*!
*@file main.qml
*@brief 主文件
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
import QtQuick 2.7
import QtQuick.Controls 2.0

ApplicationWindow {
visible: true
width: 400
height: 300
title: qsTr("Qml滑动删除")

ListModel {
id: listModel

ListElement {
text: qsTr("111222333随便的一些内容")
}
ListElement {
text: qsTr("AAABBBCCC随便的一些内容")
}
ListElement {
text: qsTr("DDDEEEFFF随便的一些内容")
}
ListElement {
text: qsTr("GGGHHHIII随便的一些内容")
}
ListElement {
text: qsTr("JJJKKKLLL随便的一些内容")
}
}

ListView{
id: listview
width: parent.width
height: parent.height
anchors.fill: parent
model: listModel
delegate: listDelegate
}

Component{
id: listDelegate
Rectangle{
id: listItem
width: parent.width
height: 30

Text {
id: text
font.family: "microsoft yahei"
font.pointSize: 12
height: parent.height
width: parent.width - delBtn.width
text: model.text
color: "green"
verticalAlignment: Text.AlignVCenter
MouseArea{
property point clickPos: "0,0"

anchors.fill: parent
onPressed: {
clickPos = Qt.point(mouse.x,mouse.y);
}
onReleased: {
var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
console.debug("delta.x: " + delta.x);
if ((delta.x < 0) && (aBtnShow.running === false) && (delBtn.width == 0)){
aBtnShow.start();
}else if (aBtnHide.running === false && (delBtn.width > 0)){
aBtnHide.start();
}
}
}
}
Rectangle{
color: "#AAAAAA"
height: 1
width: parent.width
anchors.bottom: parent.bottom
}
Rectangle{
id: delBtn
height: parent.height
width: 0
color: "#EE4040"
anchors.right: parent.right
Text {
font.family: "microsoft yahei"
font.pointSize: 12
anchors.centerIn: parent
text: qsTr("删除")
color: "#ffffff"
}
MouseArea{
anchors.fill: parent
onClicked: {
listview.model.remove(index);
}
}
}
PropertyAnimation{
id: aBtnShow
target: delBtn
property: "width"
duration: 100
from: 0
to: 60
}
PropertyAnimation{
id: aBtnHide
target: delBtn
property: "width"
duration: 100
from: 60
to: 0
}
}
}
}
5 changes: 5 additions & 0 deletions QmlListSlidDelete/qml.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
Binary file added QmlListSlidDelete/show.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions QtQuickExamples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ SUBDIRS += QmlKey
SUBDIRS += QmlLoader
SUBDIRS += QmlInvertedImage
SUBDIRS += QmlFontAwesome
SUBDIRS += QmlListSlidDelete
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ QmlFontAwesome: Qml使用FontAwesome
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFontAwesome/show.jpg?raw=true)


QmlListSlidDelete: Qml滑动删除

![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlListSlidDelete/show.gif?raw=true)

0 comments on commit c1fa6de

Please sign in to comment.