[英]QT 5.7 QML How to control which Control gets the focus within a TabView
我想安排一個特定的控件來獲得TabView
Tab
的焦點。 無論我做什么,似乎第一個得到了關注。 我試過設置focus:false
其他地方都是focus:false
,但它不起作用。
請考慮以下代碼。 我有一個包含兩個RadioButton
和一個TextField
的簡單列。 我想安排TextField
在選擇選項卡時始終獲得焦點,但它總是會轉到第一個RadioButton
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
ApplicationWindow
{
visible: true
width: 800
height: 400
TabView
{
anchors.fill: parent
Tab { title: "tab1"; sourceComponent: foo }
Tab { title: "tab2"; sourceComponent: foo }
}
Component
{
id: foo
ColumnLayout
{
spacing: 32
ExclusiveGroup { id: optionGroup }
RadioButton
{
// i always get the focus!!
exclusiveGroup: optionGroup
text: "Click me"
activeFocusOnPress: true
focus: false
}
RadioButton
{
exclusiveGroup: optionGroup
text: "No, click me!"
activeFocusOnPress: true
focus: false
}
TextField
{
// but i want the focus
placeholderText: "type here"
focus: true
}
}
}
}
按“tab2”查看,
我嘗試在TabView
強制添加,
onCurrentIndexChanged: getTab(currentIndex).item.forceActiveFocus()
但它沒有任何區別。
我已經閱讀了焦點的解釋,但在這種情況下沒有幫助。
感謝您的任何建議或幫助,
可能是一個錯誤。 請嘗試使用Qt Quick Controls 2.0 :
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 800
height: 400
header: TabBar {
id: bar
width: parent.width
TabButton {
text: qsTr("tab1")
}
TabButton {
text: qsTr("tab2")
}
}
StackLayout {
anchors.fill: parent
currentIndex: bar.currentIndex
ColumnLayout {
id: columnLayout
spacing: 32
ButtonGroup {
id: optionGroup
buttons: columnLayout.children
}
RadioButton {
text: "Click me"
}
RadioButton {
text: "No, click me!"
}
TextField {
placeholderText: "type here"
focus: true
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.