I want to customize TabButtons in QML and I couldn't find sufficient properties here.
I'm able to change the font color but how can I change the the underlying line style?
I want to customize TabButtons in QML and I couldn't find sufficient properties here.
I'm able to change the font color but how can I change the the underlying line style?
You have to implement it by yourself. You can use the same template used by Qt for the button and change whatever you want. In order to find the implentation, you can into the Qt folder. For me it's in:
C:\Qt\5.11.1\Src\qtquickcontrols2\src\imports\controls\material
Another option is to put inside the TabBar whatever you want, for example, you could do:
TabBar {
id: tabBarItem
currentIndex: model.currentIndex
contentItem: ListView {
id: view
model: model //it Contains the list of items that you want to show
delegate: delegate // Delegate that could be a button or whatever. You could use the default delegate ItemDelegate
}
}
https://doc.qt.io/qt-5/qml-qtquick-controls2-itemdelegate.html
I would propose to build your own item, which gives you more control in terms of design decisions.
To build a tab with buttons as you wish you can do something like below (Note: there is a lot of room for improvement here, so go on and experiment, you will learn a lot):
import QtQuick 2.0
Rectangle {
id: button
width: 100
height: 20
color: "#ADD8E6"
radius: 2
property alias text: buttontext
signal clicked
property bool selected
Text {
id: buttontext
anchors.centerIn: parent
text: "Test"
}
MouseArea {
id: mouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: button.clicked()
}
Rectangle {
id: underlineRect
visible: button.selected
height: 2
width: button.width
color: "black"
anchors.bottom: parent.bottom
}
Behavior on selected {PropertyAnimation {properties: "selected"; easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 0.5}}
}
Row {
id: buttonRow
spacing:2
anchors.centerIn: parent
TopButton {
id: firstButton
selected: true
onClicked: {
secondButton.selected = false
selected = true
}
}
TopButton {
id: secondButton
onClicked: {
firstButton.selected = false
selected = true
}
}
}
Rectangleor whatever attached to the bottom of the Button's content rectangle. - folibis