最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using dialogs in QML - Stack Overflow

programmeradmin1浏览0评论

What if at some moment of time I need to get user input by calling dialog window or something like that. What is the best way to implement this using QML? Any analogs of prompt in js?

What if at some moment of time I need to get user input by calling dialog window or something like that. What is the best way to implement this using QML? Any analogs of prompt in js?

Share Improve this question edited May 31, 2014 at 13:52 NG_ 7,2018 gold badges49 silver badges69 bronze badges asked May 26, 2014 at 16:42 Bolein95Bolein95 3,0562 gold badges27 silver badges31 bronze badges 2
  • 1 Are you targeting desktops, phones, or iPad type devices? – Nathaniel Johnson Commented May 26, 2014 at 16:51
  • 1 This is a pretty broad question but I think one of the approaches using a Loader will work. qt-project/wiki/QML-Application-Structuring-Approaches – Nathaniel Johnson Commented May 26, 2014 at 16:54
Add a ment  | 

1 Answer 1

Reset to default 3

You can use Dialog, available since Qt 5.3, and customize it as you wish. Ensure, that you have this version installed and working.

Here you can find example.

Also, take a look at small example I've prepared:

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: ")
        }
    }
}
发布评论

评论列表(0)

  1. 暂无评论