弹窗控件,类似于QMessageBox

属性

  1. activeFocus : bool
  2. anchors.centerIn : Object
  3. availableHeight : real
  4. availableWidth : real
  5. background : Item
  6. bottomInset : real
  7. bottomMargin : real
  8. bottomPadding : real
  9. clip : bool
  10. closePolicy : enumeration 关闭弹窗的方式
  11. contentChildren : list<Item>
  12. contentData : list<Object>
  13. contentHeight : real
  14. 内容填充
  15. contentItem : Item
  16. contentWidth : real
  17. dim : bool 非模态状态下对话框外区域背景色是否需要设置,模态的时候其他区域是深色的(可通过Overlay对弹窗外的区域进行设置)
  18. enabled : bool
  19. 打开时转变的效果
  20. enter : Transition
  21. enter: Transition {
  22. NumberAnimation {
  23. property: "opacity";
  24. from: 0.0;
  25. to: 1.0
  26. duration: 1000
  27. }
  28. }
  29. 关闭时的转变效果
  30. exit : Transition
  31. enter: Transition {
  32. NumberAnimation {
  33. property: "opacity";
  34. from: 0.0;
  35. to: 1.0
  36. duration: 1000
  37. }
  38. }
  39. focus : bool
  40. font : font
  41. height : real
  42. horizontalPadding : real
  43. implicitBackgroundHeight : real
  44. implicitBackgroundWidth : real
  45. implicitContentHeight : real
  46. implicitContentWidth : real
  47. implicitHeight : real
  48. implicitWidth : real
  49. leftInset : real
  50. leftMargin : real
  51. leftPadding : real
  52. locale : Locale
  53. margins : real
  54. mirrored : bool
  55. modal : bool 模态true后不可操作其他窗口,只有关闭窗口后才可操作其他窗口,模态时Popup.NoAutoClose慎用
  56. opacity : real
  57. opened : bool
  58. padding : real
  59. palette : palette
  60. parent : Item
  61. rightInset : real
  62. rightMargin : real
  63. rightPadding : real
  64. scale : real
  65. spacing : real
  66. topInset : real
  67. topMargin : real
  68. topPadding : real
  69. transformOrigin : enumeration
  70. verticalPadding : real
  71. visible : bool // 一个控件内套Popup 不会因为父控件是不可见的而子控件也不可见
  72. width : real
  73. x : real
  74. y : real
  75. z : real //popup作为一个弹窗,会覆盖其他类型的控件,该参数只是有效于相同类型的popup类弹窗

可见性

  1. Rectangle{
  2. width: 200
  3. height: 200
  4. color: "red"
  5. visible: false
  6. Popup{
  7. width: 100
  8. height: 60
  9. visible: true
  10. }
  11. }

image.png-》image.png

z轴顺序

Popup 将其他类型的控件都进行遮盖,不管其z顺序,popup的z只是在不同得popup对象之间有效果

  1. Rectangle{
  2. width: 200
  3. height: 200
  4. color: "red"
  5. visible: true
  6. z:1
  7. }
  8. Rectangle{
  9. width: 200
  10. height: 200
  11. x: 100
  12. color: "blue"
  13. visible: true
  14. }

默认后声明的控件z更大
image.png

  1. Popup{
  2. width: 200
  3. height: 200
  4. visible: true
  5. background: Rectangle{
  6. color: "black"
  7. }
  8. }
  9. Popup{
  10. width: 200
  11. height: 200
  12. x: 100
  13. visible: true
  14. background: Rectangle{
  15. color: "red"
  16. }
  17. z: 1
  18. }

image.png

关闭弹窗

  1. Popup{
  2. id: popup
  3. x:100
  4. y: 100
  5. width: 200
  6. height: 300
  7. visible: true
  8. closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
  9. }
  10. /**
  11. 默认点击esc 和 谈窗外空白区域可关闭,Popup.CloseOnEscape | Popup.CloseOnPressOutside
  12. Popup.NoAutoClose
  13. The popup will only close when manually instructed to do so.
  14. Popup.CloseOnPressOutside
  15. The popup will close when the mouse is pressed outside of it.
  16. Popup.CloseOnPressOutsideParent
  17. The popup will close when the mouse is pressed outside of its parent.
  18. Popup.CloseOnReleaseOutside
  19. The popup will close when the mouse is released outside of it.
  20. Popup.CloseOnReleaseOutsideParent
  21. The popup will close when the mouse is released outside of its parent.
  22. Popup.CloseOnEscape
  23. The popup will close when the escape key is pressed while the popup has active focus.
  24. */

自定义弹窗内容

  1. Popup{
  2. id: popup
  3. x:100
  4. y: 100
  5. width: 500
  6. height: 300
  7. visible: true
  8. // closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
  9. closePolicy: Popup.CloseOnEscape
  10. modal: true
  11. // dim:true
  12. enter: Transition {
  13. NumberAnimation {
  14. property: "opacity";
  15. from: 0.0;
  16. to: 1.0
  17. duration: 1000
  18. }
  19. }
  20. exit: Transition {
  21. NumberAnimation {
  22. property: "opacity";
  23. from: 1.0;
  24. to: 0.0
  25. duration: 1000
  26. }
  27. }
  28. contentItem: Rectangle{
  29. anchors.fill: parent
  30. color: "gray"
  31. Text{
  32. id: txt
  33. anchors.fill: parent
  34. text: qsTr("message box area!!!!!")
  35. font{
  36. pixelSize: 26
  37. }
  38. wrapMode: Text.WordWrap //按字换行
  39. }
  40. Button{
  41. anchors.bottom: parent.bottom
  42. anchors.bottomMargin: 30
  43. anchors.right: parent.right
  44. anchors.rightMargin: 30
  45. text: "cancel"
  46. }
  47. Button{
  48. anchors.bottom: parent.bottom
  49. anchors.bottomMargin: 30
  50. anchors.left: parent.left
  51. anchors.leftMargin: 30
  52. text: "ok"
  53. }
  54. }
  55. }

image.png

Overlay

属性

  1. modal : Component 模态的对话框
  2. modeless : Component 非模态的对话框
  3. overlay : Overlay

非模态

  1. Popup{
  2. id: popup
  3. x:100
  4. y: 100
  5. width: 400
  6. height: 300
  7. visible: true
  8. // closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
  9. closePolicy: Popup.CloseOnEscape
  10. modal: false
  11. dim:true
  12. enter: Transition {
  13. NumberAnimation {
  14. property: "opacity";
  15. from: 0.0;
  16. to: 1.0
  17. duration: 1000
  18. }
  19. }
  20. exit: Transition {
  21. NumberAnimation {
  22. property: "opacity";
  23. from: 1.0;
  24. to: 0.0
  25. duration: 1000
  26. }
  27. }
  28. contentItem: Rectangle{
  29. anchors.fill: parent
  30. color: "gray"
  31. Text{
  32. id: txt
  33. anchors.fill: parent
  34. text: qsTr("message box area!!!!!")
  35. font{
  36. pixelSize: 26
  37. }
  38. wrapMode: Text.WordWrap //按字换行
  39. }
  40. Button{
  41. anchors.bottom: parent.bottom
  42. anchors.bottomMargin: 30
  43. anchors.right: parent.right
  44. anchors.rightMargin: 30
  45. text: "cancel"
  46. }
  47. Button{
  48. anchors.bottom: parent.bottom
  49. anchors.bottomMargin: 30
  50. anchors.left: parent.left
  51. anchors.leftMargin: 30
  52. text: "ok"
  53. }
  54. }
  55. Overlay.modal: Rectangle{
  56. anchors.fill: parent
  57. color: "lightsteelblue"
  58. }
  59. Overlay.modeless: Rectangle{
  60. anchors.fill: parent
  61. color: "blue"
  62. }
  63. }

image.png

模态

  1. modal: true
  2. // dim:true

image.png

模态非弹窗区域点击

  1. Popup{
  2. id: popup
  3. x:100
  4. y: 100
  5. width: 400
  6. height: 300
  7. visible: true
  8. // closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
  9. closePolicy: Popup.CloseOnEscape
  10. modal: true
  11. // dim:true
  12. enter: Transition {
  13. NumberAnimation {
  14. property: "opacity";
  15. from: 0.0;
  16. to: 1.0
  17. duration: 1000
  18. }
  19. }
  20. exit: Transition {
  21. NumberAnimation {
  22. property: "opacity";
  23. from: 1.0;
  24. to: 0.0
  25. duration: 1000
  26. }
  27. }
  28. contentItem: Rectangle{
  29. anchors.fill: parent
  30. color: "gray"
  31. Text{
  32. id: txt
  33. anchors.fill: parent
  34. text: qsTr("message box area!!!!!")
  35. font{
  36. pixelSize: 26
  37. }
  38. wrapMode: Text.WordWrap //按字换行
  39. }
  40. Button{
  41. anchors.bottom: parent.bottom
  42. anchors.bottomMargin: 30
  43. anchors.right: parent.right
  44. anchors.rightMargin: 30
  45. text: "cancel"
  46. onClicked: {
  47. console.log("cancel")
  48. }
  49. }
  50. Button{
  51. anchors.bottom: parent.bottom
  52. anchors.bottomMargin: 30
  53. anchors.left: parent.left
  54. anchors.leftMargin: 30
  55. text: "ok"
  56. onClicked: {
  57. console.log("ok")
  58. }
  59. }
  60. }
  61. Overlay.modal: Rectangle{
  62. anchors.fill: parent
  63. // color: "lightsteelblue"
  64. color: "#33003322" //rgba
  65. Popup{
  66. width: parent.width
  67. // height: parent.height
  68. height: 90
  69. visible: true
  70. closePolicy: Popup.NoAutoClose
  71. background: Rectangle{
  72. color: "transparent" //透明色 使得下层的Popup可见
  73. // color: "gray"
  74. }
  75. Button{
  76. width: 50
  77. height: 50
  78. anchors.right: parent.right
  79. onClicked: {
  80. console.log("clicked")
  81. }
  82. }
  83. }
  84. }
  85. Overlay.modeless: Rectangle{
  86. anchors.fill: parent
  87. // color: "blue" //英文字符
  88. // color: "#202030" //rgb
  89. color: "#20323022" //rgba
  90. }
  91. }

image.png