Skip to content

Commit 6cca5d0

Browse files
committed
update
1 parent 4201961 commit 6cca5d0

11 files changed

+33
-19
lines changed

QmlTabBar/BaseTabBar.qml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,52 @@ import QtQuick.Layouts 1.0
1111

1212
TabBar {
1313
property alias myModel: myModel
14-
14+
property int lastIndex: 0
1515

1616
id: bar
17-
height: 48
18-
width: parent.width
1917
currentIndex: 0
2018

2119
ListModel {
2220
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";}
2721
}
2822

2923
Repeater {
24+
id: repeater
3025
model: myModel
3126

3227
TabButton {
28+
property alias imageSource: image.source
29+
property alias textColor: text.color
30+
3331
height: bar.height
3432
contentItem:Text{
33+
id: text
3534
text: modelText
3635
horizontalAlignment: Text.AlignHCenter
3736
verticalAlignment: Text.AlignBottom
3837
color: (model.index === bar.currentIndex) ? modelColorG : modelColor
3938
}
4039
background:Image{
40+
id: image
4141
width: 24
4242
height: 24
4343
anchors.horizontalCenter: parent.horizontalCenter
4444
source: (model.index === bar.currentIndex) ? modelSrcG : modelSrc
4545
}
46+
onHoveredChanged: {
47+
if (model.index !== bar.currentIndex){
48+
hovered ? text.color = modelColorG : text.color = modelColor
49+
hovered ? image.source = modelSrcG : image.source = modelSrc
50+
}
51+
}
52+
onClicked: {
53+
repeater.itemAt(bar.lastIndex).imageSource = myModel.get(bar.lastIndex).modelSrc;
54+
repeater.itemAt(bar.lastIndex).textColor = modelColor;
55+
56+
image.source = modelSrcG;
57+
text.color = modelColorG;
58+
bar.lastIndex = model.index;
59+
}
4660
}
4761
}
4862
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

QmlTabBar/main.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ ApplicationWindow {
2222
height: 48
2323
width: parent.width
2424
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";}
25+
myModel.append({ "modelText": "消息", "modelColor": "#000000", "modelColorG": "#148014", "modelSrc": "qrc:/images/Chat_MsgRecord.svg", "modelSrcG": "qrc:/images/Chat_MsgRecordG.svg"})
26+
myModel.append({ "modelText": "联系人", "modelColor": "#000000", "modelColorG": "#148014", "modelSrc": "qrc:/images/Chat_FriendManager.svg", "modelSrcG": "qrc:/images/Chat_FriendManagerG.svg"})
27+
myModel.append({ "modelText": "发现", "modelColor": "#000000", "modelColorG": "#148014", "modelSrc": "qrc:/images/Mobile_Find.svg", "modelSrcG": "qrc:/images/Mobile_FindG.svg"})
28+
myModel.append({ "modelText": "", "modelColor": "#000000", "modelColorG": "#148014", "modelSrc": "qrc:/images/Main_P2PChat.svg", "modelSrcG": "qrc:/images/Main_P2PChatG.svg"})
2929
}
3030
}
3131

QmlTabBar/qml.qrc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<RCC>
22
<qresource prefix="/">
33
<file>main.qml</file>
4-
<file>Chat_FriendManager.svg</file>
5-
<file>Chat_MsgRecord.svg</file>
6-
<file>Main_P2PChat.svg</file>
7-
<file>Mobile_Find.svg</file>
8-
<file>Chat_FriendManagerG.svg</file>
9-
<file>Chat_MsgRecordG.svg</file>
10-
<file>Main_P2PChatG.svg</file>
11-
<file>Mobile_FindG.svg</file>
4+
<file>images\Chat_FriendManager.svg</file>
5+
<file>images\Chat_MsgRecord.svg</file>
6+
<file>images\Main_P2PChat.svg</file>
7+
<file>images\Mobile_Find.svg</file>
8+
<file>images\Chat_FriendManagerG.svg</file>
9+
<file>images\Chat_MsgRecordG.svg</file>
10+
<file>images\Main_P2PChatG.svg</file>
11+
<file>images\Mobile_FindG.svg</file>
1212
<file>BaseTabBar.qml</file>
1313
</qresource>
1414
</RCC>

0 commit comments

Comments
 (0)