-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseTabBar.qml
54 lines (49 loc) · 1.6 KB
/
BaseTabBar.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*底部按钮*/
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
TabBar{
property alias myModel: myModel
property int lastIndex: 0
id:bar
currentIndex: 0
ListModel{
id:myModel
}
Repeater{
id:repeater
model: myModel
TabButton{
property alias imageSource:image.source
property alias textColor: text.color
height: bar.height
contentItem: Text{
id:text
text: modelText
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
color: (model.index===bar.currentIndex)?modelSrcG:modelSrc
}
background:Image{
id: image
width: 24
height: 24
anchors.horizontalCenter: parent.horizontalCenter
source: (model.index === bar.currentIndex) ? modelSrcG : modelSrc
}
onHoveredChanged: {
if(model.index!==bar.currentIndex){
hovered ? text.color = modelColorG : text.color = modelColor
hovered ? image.source = modelSrcG : image.source = modelSrc
}
}
onClicked: {
repeater.itemAt(bar.lastIndex).imageSource = myModel.get(bar.lastIndex).modelSrc;
repeater.itemAt(bar.lastIndex).textColor = modelColor;
image.source = modelSrcG;
text.color = modelColorG;
bar.lastIndex = model.index;
}
}
}
}