【问题标题】:Using dialogs in QML在 QML 中使用对话框
【发布时间】:2014-05-26 16:42:39
【问题描述】:

如果在某个时刻我需要通过调用对话框窗口或类似的东西来获取用户输入怎么办。使用 QML 实现这一点的最佳方法是什么? js中有prompt的类似物吗?

【问题讨论】:

标签: javascript qt qml qt5 qtquickcontrols


【解决方案1】:

您可以使用自 Qt 5.3 起提供的Dialog,并根据需要对其进行自定义。 确保您已安装并运行此版本。

Here你可以找到例子。

另外,看看我准备的小例子:

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: ")
        }
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-29
  • 2011-10-08
相关资源
最近更新 更多