PromptDialog.qml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick.Controls
  5. import QtQuick.Layouts
  6. Dialog {
  7. property alias text: message.text
  8. property alias prompt: field.text
  9. property bool handled: false
  10. signal input(string text)
  11. title: qsTr("Prompt Dialog")
  12. modal: false
  13. anchors.centerIn: parent
  14. objectName: "promptDialog"
  15. function acceptDialog() {
  16. input(field.text);
  17. accept();
  18. }
  19. ColumnLayout {
  20. id: rootLayout
  21. anchors.fill: parent
  22. anchors.margins: 4
  23. property int minimumWidth: rootLayout.implicitWidth + rootLayout.doubleMargins
  24. property int minimumHeight: rootLayout.implicitHeight + rootLayout.doubleMargins
  25. property int doubleMargins: anchors.margins * 2
  26. SystemPalette { id: palette; colorGroup: SystemPalette.Active }
  27. Text {
  28. id: message
  29. Layout.fillWidth: true
  30. color: palette.windowText
  31. textFormat: Text.PlainText
  32. }
  33. TextField {
  34. id:field
  35. focus: true
  36. Layout.fillWidth: true
  37. onAccepted: acceptDialog()
  38. }
  39. Item {
  40. Layout.fillHeight: true
  41. }
  42. RowLayout {
  43. Layout.alignment: Qt.AlignRight
  44. spacing: 8
  45. Button {
  46. text: qsTr("OK")
  47. onClicked: acceptDialog()
  48. }
  49. Button {
  50. text: qsTr("Cancel")
  51. onClicked: reject()
  52. }
  53. }
  54. }
  55. }