2016-08-05 8 views
1

TabViewTab 내에서 포커스를 얻으려면 특정 컨트롤을 준비하고 싶습니다. 첫 번째 것은 내가하는 일과 관계없이 포커스를 얻는 것 같습니다. 다른 곳에서는 focus:false으로 설정을 시도했지만 작동하지 않습니다.QT 5.7 QML 어떤 컨트롤이 TabView 내에서 포커스를 얻는 지 제어하는 ​​방법

다음 코드를 고려하십시오. 두 개의 RadioButtonTextField을 포함하는 간단한 열이 있습니다. 내가 탭을 선택하면 항상 초점을 얻을 수있는 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"로 이동

enter image description here

나는 추가하여 TabView 내에서 강제로 시도

onCurrentIndexChanged: getTab(currentIndex).item.forceActiveFocus()

하지만 차이는 없습니다.

초점 설명을 읽었지만이 경우 도움이되지 않았습니다. 어떤 제안이나 도움을

감사합니다, 아마

답변

0

버그. 대신 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 
      } 
     } 
    } 
} 
+0

난 당신이 :-) A는 컨트롤의 몸 내가 변경하기를 꺼려 해요 1 개 코드에서이 문제를 고려하는 것이 언급하지 않았다 희망했다. 그러나 귀하의 답변을 시도해보고 일부 컨트롤 2를 혼합하여 수정할 수 있는지 확인해 보겠습니다. 감사. –

+0

이것은 답변입니다. 맞습니다.'Tab's가 로더이기 때문에 결코'TabView'를 좋아하지 않은'StackLayout'을 사용하는 것이 더 낫습니다. StackLayout 내부 Controls1 사용하고 잘 작동합니다. 감사. –