当前位置:   article > 正文

QML StackLayout_stacklayout qml 官网

stacklayout qml 官网

QML StackLayout

示例

  1. import QtQuick 2.14
  2. import QtQuick.Window 2.14
  3. import QtQuick.Controls 2.5
  4. import QtQuick.Layouts 1.15
  5. import "./common.js" as FunJs
  6. Window
  7. {
  8. id: window
  9. width: 600
  10. height: 480
  11. visible: true
  12. title: "QML Demo"
  13. Item
  14. {
  15. id: rootItem
  16. anchors.fill: parent
  17. property var colorBuilder: FunJs.getColorBudider(Qt.rgba)
  18. Row
  19. {
  20. id: header
  21. Component
  22. {
  23. id: menuButton
  24. Button
  25. {
  26. required property string menuText
  27. required property var layout
  28. required property int index
  29. text: menuText
  30. onClicked:
  31. {
  32. layout.currentIndex = index
  33. }
  34. }
  35. }
  36. Component.onCompleted:
  37. {
  38. let munu = ["Home", "Help"]
  39. munu.forEach(function(item, index)
  40. {
  41. menuButton.createObject(header, {layout:stacklayout, menuText:item, index: index})
  42. }
  43. )
  44. }
  45. }
  46. StackLayout {
  47. id: stacklayout
  48. anchors.top: header.bottom
  49. anchors.bottom: parent.bottom
  50. anchors.left: parent.left
  51. anchors.right: parent.right
  52. Component
  53. {
  54. id: pageComponent
  55. Rectangle{}
  56. }
  57. Component.onCompleted:
  58. {
  59. for(let i = 0; i < 2; ++i)
  60. {
  61. pageComponent.createObject(stacklayout, {color: rootItem.colorBuilder()})
  62. }
  63. }
  64. }
  65. }
  66. }
  • 效果:

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/334704
推荐阅读
相关标签
  

闽ICP备14008679号