QML --》 GridView(网格视图)

import QtQuick 2.0

Rectangle{
    width: 240;
    height: 300;
    color: "white"
    GridView{
        anchors.fill: parent
        anchors.margins: 20

        clip: true  // 设置clip属性为true,来激活裁剪功能

        model:40
        delegate: numberDelegate
        cellHeight: 45
        cellWidth: 45
        header: headerComponent    // 页眉
        footer: footerComponent    // 页脚
    }
    Component{
        id:headerComponent
        Rectangle{
            width: 40;
            height: 20;
            color: "yellow"
        }
    }
    Component{
        id:footerComponent
        Rectangle{
            width: 40;
            height: 20;
            color: "yellow"
        }
    }
    Component{
        id:numberDelegate
        Rectangle{
            width: 40;
            height: 40;
            color: "lightGreen"
            Text {
                anchors.centerIn: parent
                font.pixelSize: 10
                text: index
            }
        }
    }
}

 

posted on 2021-08-12 14:35  缘随风烬  阅读(802)  评论(0编辑  收藏  举报