Francisco Hernandez
Francisco Hernandez

Reputation: 312

How to force active focus/select QML Tab under QML TabView?

I have a TabView with 3 Tabs and I want to change the focus/select the third Tab when a button is pressed. I've tried forceActiveFocus, but it does not work.

//.qml
TabView {
    Tab {
        id: redTab
        title: "Red"
        Rectangle { color: "red" }
    }
    Tab {
        id: blueTab
        title: "Blue"
        Rectangle { color: "blue" }
    }
    Tab {
        id: greenTab
        title: "Green"
        Rectangle { color: "green" }
    }
}

ToolButton {
    inconSource: "lock.png"
    onClicked: {
        greenTab.forceActiveFocus() // does not work?
    }
}    

Upvotes: 0

Views: 857

Answers (1)

jpnurmi
jpnurmi

Reputation: 5836

Set the currentIndex:

TabView {
    id: tabView
    //...
}
//...
tabView.currentIndex = 2

Upvotes: 3

Related Questions