Search code examples
qtqmlqt5qtquick2qtquickcontrols

How to arrange tabs of TabView in multiple rows?


From: http://doc.qt.io/qt-5/qml-qtquick-controls-tabview.html#details

TabView 
{
    Tab {
        title: "Red"
        Rectangle { color: "red" }
    }
    Tab {
        title: "Blue"
        Rectangle { color: "blue" }
    }
    Tab {
        title: "Green"
        Rectangle { color: "green" }
    }
}

These tabs get by default shown in a horizontal bar. How to display them in separate rows?

Like this:
Tab1
Tab2
Tab3

Rather than:
Tab1 Tab2 Tab3


Solution

  • You need to hide standard tab bar, and create your own vertical bar.

    Row {
        Column {
            Repeater {
                model: view.count
                Rectangle {
                    width: 100
                    height: 40
                    border.width: 1
                    Text {
                        anchors.centerIn: parent
                        text: view.getTab(index).title
                    }
                    MouseArea {
                        anchors.fill: parent
                        cursorShape: Qt.PointingHandCursor
                        onClicked: view.currentIndex = index
                    }
                }
            }
        }
        TabView {
            id: view
            style: TabViewStyle {
                tab: Item {}
            }
    
            Tab {
                title: "Red"
                Rectangle { color: "red" }
            }
            Tab {
                title: "Blue"
                Rectangle { color: "blue" }
            }
            Tab {
                title: "Green"
                Rectangle { color: "green" }
            }
        }
    }