如何在QML TabView下强制激活焦点/选择QML选项卡?

时间:2016-11-02 21:02:00

标签: qml qtquick2 qtquickcontrols

我有一个TabView,其中包含3 Tab秒,我想更改焦点/按下按钮时选择第三个Tab。我已经尝试了forceActiveFocus,但它不起作用。

//.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?
    }
}    

1 个答案:

答案 0 :(得分:3)

设置currentIndex

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