2017-08-02 7 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 
     } 
    } 
}