3

ダイアログウィンドウなどを呼び出してユーザー入力を取得する必要がある場合はどうでしょうか。QMLを使用してこれを実装する最良の方法は何ですか? promptjsの類似物はありますか?

4

1 に答える 1

2

Qt 5.3 以降Dialogで利用可能なを使用して、必要に応じてカスタマイズできます。 このバージョンがインストールされ、動作していることを確認してください。

ここで例を見つけることができます。

また、私が準備した小さな例を見てください。

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 に答える