Skip to content

Commit 4201961

Browse files
committed
update
1 parent 3ffaee4 commit 4201961

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

QmlTabBar/BaseTabBar.qml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*!
2+
*@file BaseTabBar.qml
3+
*@brief 自定义TabBar
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+
import QtQuick.Layouts 1.0
11+
12+
TabBar {
13+
property alias myModel: myModel
14+
15+
16+
id: bar
17+
height: 48
18+
width: parent.width
19+
currentIndex: 0
20+
21+
ListModel {
22+
id: myModel
23+
// ListElement { modelText: "消息"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Chat_MsgRecord.svg"; modelSrcG: "qrc:/Chat_MsgRecordG.svg";}
24+
// ListElement { modelText: "联系人"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Chat_FriendManager.svg"; modelSrcG: "qrc:/Chat_FriendManagerG.svg";}
25+
// ListElement { modelText: "发现"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Mobile_Find.svg"; modelSrcG: "qrc:/Mobile_FindG.svg";}
26+
// ListElement { modelText: "我"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Main_P2PChat.svg"; modelSrcG: "qrc:/Main_P2PChatG.svg";}
27+
}
28+
29+
Repeater {
30+
model: myModel
31+
32+
TabButton {
33+
height: bar.height
34+
contentItem:Text{
35+
text: modelText
36+
horizontalAlignment: Text.AlignHCenter
37+
verticalAlignment: Text.AlignBottom
38+
color: (model.index === bar.currentIndex) ? modelColorG : modelColor
39+
}
40+
background:Image{
41+
width: 24
42+
height: 24
43+
anchors.horizontalCenter: parent.horizontalCenter
44+
source: (model.index === bar.currentIndex) ? modelSrcG : modelSrc
45+
}
46+
}
47+
}
48+
}

QmlTabBar/main.qml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,15 @@ ApplicationWindow {
1717
height: 400
1818
title: qsTr("Qml底部导航")
1919

20-
footer: TabBar {
20+
footer: BaseTabBar{
2121
id: bar
2222
height: 48
2323
width: parent.width
24-
currentIndex: 0
25-
26-
ListModel {
27-
id: myModel
28-
ListElement { modelText: "消息"; modelSrc: "qrc:/Chat_MsgRecord.svg"; modelSrcG: "qrc:/Chat_MsgRecordG.svg";}
29-
ListElement { modelText: "联系人"; modelSrc: "qrc:/Chat_FriendManager.svg"; modelSrcG: "qrc:/Chat_FriendManagerG.svg";}
30-
ListElement { modelText: "发现"; modelSrc: "qrc:/Mobile_Find.svg"; modelSrcG: "qrc:/Mobile_FindG.svg";}
31-
ListElement { modelText: ""; modelSrc: "qrc:/Main_P2PChat.svg"; modelSrcG: "qrc:/Main_P2PChatG.svg";}
32-
}
33-
34-
Repeater {
35-
model: myModel
36-
37-
TabButton {
38-
height: bar.height
39-
contentItem:Text{
40-
text: modelText
41-
horizontalAlignment: Text.AlignHCenter
42-
verticalAlignment: Text.AlignBottom
43-
color: (model.index === bar.currentIndex) ? "#148014" : "#000000"
44-
}
45-
background:Image{
46-
width: 24
47-
height: 24
48-
anchors.horizontalCenter: parent.horizontalCenter
49-
source: (model.index === bar.currentIndex) ? modelSrcG : modelSrc
50-
}
51-
}
24+
Component.onCompleted: {
25+
myModel.append({ "modelText": "消息", "modelColor": "#000000", "modelColorG": "#148014", "modelSrc": "qrc:/Chat_MsgRecord.svg", "modelSrcG": "qrc:/Chat_MsgRecordG.svg"})
26+
myModel.append({ modelText: "联系人"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Chat_FriendManager.svg"; modelSrcG: "qrc:/Chat_FriendManagerG.svg";}
27+
// ListElement { modelText: "发现"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Mobile_Find.svg"; modelSrcG: "qrc:/Mobile_FindG.svg";}
28+
// ListElement { modelText: "我"; modelColor: "#000000"; modelColorG: "#148014"; modelSrc: "qrc:/Main_P2PChat.svg"; modelSrcG: "qrc:/Main_P2PChatG.svg";}
5229
}
5330
}
5431

QmlTabBar/qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<file>Chat_MsgRecordG.svg</file>
1010
<file>Main_P2PChatG.svg</file>
1111
<file>Mobile_FindG.svg</file>
12+
<file>BaseTabBar.qml</file>
1213
</qresource>
1314
</RCC>

0 commit comments

Comments
 (0)