本文介绍了设置 Qml TabBar 选项卡颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用此代码设置 TabBar 选项卡背景颜色,但仅更改了选定的选项卡颜色.如何为其他选项卡设置颜色?另外,如何设置标签的文本颜色?
I tried this code to set TabBar tab background color but only selected tab color is changed. How can I set color for other tabs? Also, how can I set text color for tabs?
TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
background: Rectangle {
color: "#f4d37c"
}
TabButton {
id: cardsTabButton
height: Style.line2Height
text: qsTr("Cards")
}
TabButton {
id: errorsTabButton
height: Style.line2Height
text: qsTr("Errors")
}
}
(左侧标签被选中)
推荐答案
您可以自定义任何QML.2控件,包括TabBar
.有关详细信息,请参阅 此 页面.简单例子:
You can customize any of QML.2 control, include TabBar
. See this page for more info. Simple example:
TabBar {
id: tabBar
anchors.fill: parent
background: Rectangle {
color: "yellow"
}
TabButton {
height: 30
text: "Tab1"
background: Rectangle {
color: tabBar.currentIndex == 0 ? "orange" : "green"
radius: 10
}
}
TabButton {
height: 30
text: "Tab2"
background: Rectangle {
color: tabBar.currentIndex == 1 ? "purple" : "lightblue"
radius: 10
}
}
}
这篇关于设置 Qml TabBar 选项卡颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!