• 4043阅读
  • 4回复

zhengtianzuo系列-Qml滑动删除 [复制链接]

上一主题 下一主题
离线zhengtianzuo
 

只看楼主 倒序阅读 楼主  发表于: 2017-11-11
```
    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
            }
        }
    }
```



需要完整代码请访问 QtQuickExamples
博客地址: https://blog.csdn.net/zhengtianzuo06
Github: https://github.com/zhengtianzuo
个人产品: https://github.com/zhengtianzuo/Silk
产品网站: http://www.camelstudio.cn
离线未知数

只看该作者 1楼 发表于: 2017-11-14
离线angelus

只看该作者 2楼 发表于: 2017-11-14
这个有点意思!
离线big_mouse

只看该作者 3楼 发表于: 2020-04-23
离线zipl1985

只看该作者 4楼 发表于: 2022-07-23
看着不错,谢谢
快速回复
限100 字节
 
上一个 下一个