【发布时间】:2017-05-07 21:16:29
【问题描述】:
我试图在 QML 中实现一个选项卡式 Dialog 以将其重置为初始值。
由于选项卡是动态实例化的,因此任何直接的方法似乎都不起作用。父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
}
}
}
}
}
}
}
【问题讨论】:
-
为什么
Combobox不能引用外部对话框?
标签: qt dialog qml qtquick2 qtquickcontrols