2017-08-02 530 views
0

我試過這段代碼來設置TabBar選項卡的背景顏色,但只有選定的選項卡顏色被更改。我怎樣才能爲其他標籤設置顏色?另外,如何設置製表符的文字顏色?設置Qml TabBar標籤顏色?

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") 
    } 
} 

Result of the code(左標籤被選中)

回答

1

可以定製任何QML.2控制的,包括TabBar。有關更多信息,請參閱this頁面。簡單示例:

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 
     } 
    } 
}