qml GridView伸展与收缩动画

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("GridView")

    ListModel {
        id: gridViewModel
        ListElement{nameText: "red"; colorValue: "red";}
        ListElement{nameText: "green"; colorValue: "green";}
        ListElement{nameText: "blue"; colorValue: "blue";}
        ListElement{nameText: "yellow"; colorValue: "yellow";}
        ListElement{nameText: "cyan"; colorValue: "cyan";}
        ListElement{nameText: "magenta"; colorValue: "magenta";}
    }

    GridView {
        id: gridView;
        width: 100; height: 150
        cellWidth: 50; cellHeight: 50
        anchors{top: parent.top; left: parent.left;}
        model: gridViewModel
        clip: true  //这个属性非常重要,不设置,动画不平滑
        interactive: false; //元素不可拖动
        focus: true
        delegate: Rectangle {
            width: 50; height: 50;
            color: colorValue
            Text {
                text: nameText; anchors.centerIn: parent
                color: "white"; font.pixelSize: 12
            }
        }
    }

    NumberAnimation {
        id: gridViewLeftToRight
        target: gridView; property: "width";
        from: 100; to: 10
        duration: 300; easing.type: Easing.InOutQuad
    }
    NumberAnimation {
        id: gridViewRightToLeft
        target: gridView; property: "width";
        from: 10; to: 100
        duration: 300; easing.type: Easing.InOutQuad
    }

    //左到右
    Rectangle {
        id: leftToRightButton
        width: 50; height: 50;
        color: "red"
        anchors{right: parent.right; rightMargin: 150; bottom: parent.bottom}
        Text { color: "white"; text: qsTr("左到右"); anchors.centerIn: parent}
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log("gridViewLeftToRight Clicked==============");
                gridViewLeftToRight.start()
            }
        }
    }

    //右到左
    Rectangle {
        id: rightToLeftButton
        width: 50; height: 50;
        color: "green"
        //color: Qt.rgba(0.1, 0.1, 0.1, 0.3)
        anchors{right: parent.right; rightMargin: 100; bottom: parent.bottom}
        Text { color: "white"; text: qsTr("右到左"); anchors.centerIn: parent}
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log("gridViewRightToLeft Clicked==============");
                gridViewRightToLeft.start()
            }
        }
    }
    //向上
    NumberAnimation {
        id: gridViewUp
        target: gridView; property: "height";
        from: 150; to: 0
        duration: 500; easing.type: Easing.InOutQuad
    }
    //向下
    NumberAnimation {
        id: gridViewDown
        target: gridView; property: "height";
        from: 0; to: 150
        duration: 500; easing.type: Easing.InOutQuad
    }

    //向上按钮
    Rectangle {
        id: pullUpButton
        width: 50; height: 50;
        color: "red"
        anchors{right: parent.right; rightMargin: 50; bottom: parent.bottom}
        Text { color: "white"; text: qsTr("向上"); anchors.centerIn: parent}
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log("gridViewUp Clicked==============");
                gridViewUp.start()
            }
        }
    }

    //向下按钮
    Rectangle {
        id: pullDownButton
        width: 50; height: 50;
        color: "green"
        anchors{right: parent.right; bottom: parent.bottom}
        Text { color: "white"; text: qsTr("向下"); anchors.centerIn: parent}
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log("gridViewDown Clicked==============");
                gridViewDown.start()
            }
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值