Javascript 在QML中使用对话框
如果在某个时刻,我需要通过调用对话框窗口或类似的方式获取用户输入,该怎么办。使用QML实现此功能的最佳方法是什么?js?中的Javascript 在QML中使用对话框,javascript,qt,qml,qt5,qtquickcontrols,Javascript,Qt,Qml,Qt5,Qtquickcontrols,如果在某个时刻,我需要通过调用对话框窗口或类似的方式获取用户输入,该怎么办。使用QML实现此功能的最佳方法是什么?js?中的提示符的任何类似项都可以使用,自Qt5.3以来就可以使用,并根据需要进行自定义。 请确保已安装此版本并正常工作 你可以找到例子 另外,看看我准备的小例子: import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Dialogs 1.2 ApplicationWindow { visible: tr
提示符的任何类似项都可以使用,自Qt5.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: ")
}
}
}
你的目标是台式机、手机还是iPad类型的设备?这是一个相当广泛的问题,但我认为使用加载器的方法之一会奏效。实际上,对话框组件甚至在5.3之前就已经可用了,尽管是在实验状态下。请参阅顶部的行自:Qt 5.2
。示例链接已失效。works@PΞdrolus感谢您的关注。已经更新了链接。