Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Qml TabBar tab color?

Tags:

qml

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

Result of the code (left tab is selected)

like image 754
Divano Avatar asked Aug 02 '17 12:08

Divano


1 Answers

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
        }
    }
}
like image 186
folibis Avatar answered Sep 22 '22 12:09

folibis