如果在某个时刻我需要通过调用对话框窗口或类似的东西来获取用户输入怎么办。使用 QML 实现这一点的最佳方法是什么?prompt
js中的任何类似物?
问问题
5182 次
1 回答
2
您可以使用Dialog
,自 Qt 5.3 起可用,并根据需要对其进行自定义。
确保您已安装并运行此版本。
在这里您可以找到示例。
另外,看看我准备的小例子:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2
ApplicationWindow {
visible: true
width: 320
height: 240
title: qsTr("Custom Dialog")
Dialog {
id: customDialog
title: "Custom Dialog in QML/Qt 5.3"
standardButtons: StandardButton.Ok | StandardButton.Cancel
Column {
anchors.fill: parent
Text {
text: "Here goes all your custom elements..."
}
TextInput {
id: edtInput
text: "Input text"
}
}
onButtonClicked: {
if (clickedButton==StandardButton.Ok) {
console.log("Accepted " + clickedButton)
lblResults.text += edtInput.text
} else {
console.log("Rejected" + clickedButton)
}
}
}
Column {
anchors.fill: parent
Button {
text: qsTr("Call Custom dialog")
onClicked: customDialog.open()
}
Text {
id: lblResults
text: qsTr("Results: ")
}
}
}
于 2014-05-31T15:01:01.613 回答