2017-05-07 5 views
0

QMLにタブ付きDialogを実装しようとしましたが、これを初期値にリセットする手段がありました。QMLリセットダイアログ(タブビュー付き)

タブは動的にインスタンス化されるため、まっすぐ進む方法のどれも動作していないようです。親Dialogは内部Comboboxを参照できず、Comboboxは外部Dialogを参照できません。これはどのように達成できますか?

import QtQuick 2.3 
import QtQuick.Controls 1.4 
import QtQuick.Dialogs 1.2 
import QtQuick.Layouts 1.1 

Dialog { 
    id: dlg 
    title: "Settings" 
    visible: true 
    standardButtons: StandardButton.Apply | StandardButton.Reset 
    property string val: "" 
    onApply: console.log(val) 
    onReset: { 
     // RESET COMBOBOX TO DEFAULT 
    } 
    TabView { 
     id: tabView 
     anchors.fill: parent 
     Tab { 
      title: "ValueTab" 
      id: tabVal 
      GridLayout { 
       id: gridVal 
       anchors.fill: parent 
       GroupBox { 
        title: qsTr("Choose value") 
        id: gb 
        Layout.fillWidth: true 
        ColumnLayout { 
         anchors.fill: parent 
         id: cl 
         ComboBox { 
          id: valueChooser 
          editable: false 
          model: ListModel { 
           id: listModel 
           ListElement { text: "One" } 
           ListElement { text: "Two" } 
           ListElement { text: "Three" } 
          } 
          Layout.fillWidth: true 
          onCurrentTextChanged : val = currentText 
         } 
        } 
       } 
      } 
     } 
    } 
} 
+0

なぜ 'Combobox'は、外側のダイアログを参照することはできませんか? – derM

答えて

0

私は私はあなたが言う権利としてあなたの質問を得た場合、あなたはCombobox内からDialogを参照することはできません、非常にわからないと思います。私はその理由を見ることができません。

あなたの問題が実際にあなたの問題を含んでいると仮定し、リセットボタンを押すと値をリセットして元の値を知っていればいいと思います。 Combobox内からDialogreset()に接続するためにConnections型を使用し

import QtQuick 2.3 
import QtQuick.Controls 1.4 
import QtQuick.Dialogs 1.2 
import QtQuick.Layouts 1.1 

Dialog { 
    id: dlg 
    title: "Settings" 
    visible: true 
    standardButtons: StandardButton.Apply | StandardButton.Reset 
    property string val: "" 
    onApply: console.log(val) 
    onReset: { 
     // **DONT** RESET COMBOBOX TO DEFAULT **HERE** 
    } 
    TabView { 
     id: tabView 
     anchors.fill: parent 
     Tab { 
      title: "ValueTab" 
      id: tabVal 
      GridLayout { 
       id: gridVal 
       anchors.fill: parent 
       GroupBox { 
        title: qsTr("Choose value") 
        id: gb 
        Layout.fillWidth: true 
        ColumnLayout { 
         anchors.fill: parent 
         id: cl 
         ComboBox { 
          id: valueChooser 
          editable: false 
          model: ListModel { 
           id: listModel 
           ListElement { text: "One" } 
           ListElement { text: "Two" } 
           ListElement { text: "Three" } 
          } 
          Layout.fillWidth: true 
          onCurrentTextChanged : val = currentText 

          /// *** INTERESTING PART HERE! *** 
          Connections { 
           target: dlg 
           onReset: { 
            // RESET COMBOBOX TO DEFAULT **HERE** INSTEAD 
            valueChooser.currentIndex = 0 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 
+0

恐ろしい:)これは、ありがとう、多くの作品! –

関連する問題