Skip to content

Commit 97ce93d

Browse files
committed
Add QmlPageNavigation
1 parent 11a5295 commit 97ce93d

File tree

9 files changed

+198
-0
lines changed

9 files changed

+198
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*!
2+
*@file QmlPageNavigation.qml
3+
*@brief Qml分页显示
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
11+
Row{
12+
id: pageNavigation
13+
property int nCout: 1
14+
property int nCurPage: 1
15+
property int nPageSize: 1
16+
17+
signal sCurPage(int curPage);
18+
19+
Rectangle{
20+
id: prevPage
21+
height: 24
22+
width: 60
23+
color: "#EEEEEE"
24+
border.color: "#AAAAAA"
25+
border.width: 1
26+
Row{
27+
anchors.centerIn: parent
28+
Image{
29+
height: 16
30+
width: 16
31+
anchors.verticalCenter: parent.verticalCenter
32+
source: "qrc:/arrow.png"
33+
rotation: -180
34+
}
35+
Text {
36+
font.family: "microsoft yahei"
37+
font.pixelSize: 12
38+
anchors.verticalCenter: parent.verticalCenter
39+
text: qsTr("上一页")
40+
}
41+
}
42+
MouseArea{
43+
anchors.fill: parent
44+
onClicked: {
45+
if (pageNavigation.nCurPage > 1) pageNavigation.nCurPage--;
46+
}
47+
}
48+
}
49+
50+
Repeater{
51+
id: repeater
52+
model: pageNavigation.nPageSize
53+
delegate: Rectangle{
54+
property int nCurIndex: (pageNavigation.nCurPage-1)*pageNavigation.nPageSize + index + 1
55+
property bool hasPage: nCurIndex <= pageNavigation.nCout
56+
57+
height: 24
58+
width: 24
59+
color: hasPage ? "#EEEEEE" : "transparent"
60+
border.color: "#AAAAAA"
61+
border.width: hasPage ? 1 : 0
62+
Text {
63+
font.family: "microsoft yahei"
64+
font.pixelSize: 12
65+
anchors.centerIn: parent
66+
text: nCurIndex
67+
visible: hasPage ? true : false
68+
}
69+
MouseArea{
70+
anchors.fill: parent
71+
hoverEnabled: hasPage
72+
onEntered: {
73+
parent.color = "#148014"
74+
}
75+
onExited: {
76+
parent.color = "#EEEEEE"
77+
}
78+
onPressed: {
79+
emit: sCurPage(nCurIndex);
80+
}
81+
}
82+
}
83+
}
84+
85+
Rectangle{
86+
id: nextPage
87+
height: 24
88+
width: 60
89+
color: "#EEEEEE"
90+
border.color: "#AAAAAA"
91+
border.width: 1
92+
Row{
93+
anchors.centerIn: parent
94+
Text {
95+
font.family: "microsoft yahei"
96+
font.pixelSize: 12
97+
anchors.verticalCenter: parent.verticalCenter
98+
text: qsTr("下一页")
99+
}
100+
Image{
101+
height: 16
102+
width: 16
103+
anchors.verticalCenter: parent.verticalCenter
104+
source: "qrc:/arrow.png"
105+
}
106+
}
107+
MouseArea{
108+
anchors.fill: parent
109+
onClicked: {
110+
if (pageNavigation.nCurPage*pageNavigation.nPageSize <= pageNavigation.nCout) pageNavigation.nCurPage++;
111+
}
112+
}
113+
}
114+
}

QmlPageNavigation/arrow.png

206 Bytes
Loading

QmlPageNavigation/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlPageNavigation/main.qml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
11+
ApplicationWindow {
12+
visible: true
13+
width: 400
14+
height: 300
15+
title: qsTr("Qml分页显示")
16+
17+
Text {
18+
id: txtPage
19+
anchors.centerIn: parent
20+
font.family: "microsoft yahei"
21+
font.pixelSize: 20
22+
text: qsTr("第1页")
23+
}
24+
25+
QmlPageNavigation{
26+
id: pageNavigation
27+
anchors.left: parent.left
28+
anchors.leftMargin: 6
29+
anchors.bottom: parent.bottom
30+
anchors.bottomMargin: 6
31+
nCout: 23
32+
nCurPage: 1
33+
nPageSize: 5
34+
onSCurPage: {
35+
txtPage.text = qsTr("") + curPage + qsTr("");
36+
}
37+
}
38+
}

QmlPageNavigation/qml.qrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>arrow.png</file>
5+
<file>QmlPageNavigation.qml</file>
6+
</qresource>
7+
</RCC>

QmlPageNavigation/show.gif

86.8 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ SUBDIRS += QmlInvertedImage
4040
SUBDIRS += QmlFontAwesome
4141
SUBDIRS += QmlListSlidDelete
4242
SUBDIRS += QmlCircularProgressButton
43+
SUBDIRS += QmlPageNavigation

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,8 @@ QmlCircularProgressButton: Qml圆形进度按钮
182182

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

185+
186+
QmlPageNavigation: Qml分页显示
187+
188+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlPageNavigation/show.gif?raw=true)
189+

0 commit comments

Comments
 (0)