• 3967阅读
  • 2回复

zhengtianzuo系列-Qml分页显示 [复制链接]

上一主题 下一主题
离线zhengtianzuo
 

只看楼主 倒序阅读 楼主  发表于: 2017-11-14
```
Row{
    id: pageNavigation
    property int nCout: 1
    property int nCurPage: 1
    property int nPageSize: 1

    signal sCurPage(int curPage);

    Rectangle{
        id: prevPage
        height: 24
        width: 60
        color: "#EEEEEE"
        border.color: "#AAAAAA"
        border.width: 1
        Row{
            anchors.centerIn: parent
            Image{
                height: 16
                width: 16
                anchors.verticalCenter: parent.verticalCenter
                source: "qrc:/arrow.png"
                rotation: -180
            }
            Text {
                font.family: "microsoft yahei"
                font.pixelSize: 12
                anchors.verticalCenter: parent.verticalCenter
                text: qsTr("上一页")
            }
        }
        MouseArea{
            anchors.fill: parent
            onClicked: {
                if (pageNavigation.nCurPage > 1) pageNavigation.nCurPage--;
            }
        }
    }

    Repeater{
        id: repeater
        model: pageNavigation.nPageSize
        delegate: Rectangle{
            property int nCurIndex: (pageNavigation.nCurPage-1)*pageNavigation.nPageSize + index + 1
            property bool hasPage: nCurIndex <= pageNavigation.nCout

            height: 24
            width: 24
            color: hasPage ? "#EEEEEE" : "transparent"
            border.color: "#AAAAAA"
            border.width: hasPage ? 1 : 0
            Text {
                font.family: "microsoft yahei"
                font.pixelSize: 12
                anchors.centerIn: parent
                text: nCurIndex
                visible: hasPage ? true : false
            }
            MouseArea{
                anchors.fill: parent
                hoverEnabled: hasPage
                onEntered: {
                    parent.color = "#148014"
                }
                onExited: {
                    parent.color = "#EEEEEE"
                }
                onPressed: {
                    emit: sCurPage(nCurIndex);
                }
            }
        }
    }

    Rectangle{
        id: nextPage
        height: 24
        width: 60
        color: "#EEEEEE"
        border.color: "#AAAAAA"
        border.width: 1
        Row{
            anchors.centerIn: parent
            Text {
                font.family: "microsoft yahei"
                font.pixelSize: 12
                anchors.verticalCenter: parent.verticalCenter
                text: qsTr("下一页")
            }
            Image{
                height: 16
                width: 16
                anchors.verticalCenter: parent.verticalCenter
                source: "qrc:/arrow.png"
            }
        }
        MouseArea{
            anchors.fill: parent
            onClicked: {
                if (pageNavigation.nCurPage*pageNavigation.nPageSize <= pageNavigation.nCout) pageNavigation.nCurPage++;
            }
        }
    }
}
```



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

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

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