• QT之QML开发 行列布局,流布局,网格布局


          本节将演示一下QML布局之行列布局,流布局和网格布局

    目录

    1.行列布局

    1.1一列多行

    1.2 一行多列

    2.流布局

    2.1 从左向右(默认)

    ​编辑

    2.2 从上往下

    3.网格布局


    1.行列布局

    1.1一列多行

    1. // 行列布局
    2. import QtQuick 2.15
    3. import QtQuick.Window 2.15
    4. import QtQuick.Controls 2.15
    5. Window {
    6. width: 640
    7. height: 480
    8. visible: true
    9. title: qsTr("Hello World")
    10. Item {
    11. anchors.fill: parent
    12. // 一列
    13. Column {
    14. spacing: 20
    15. // 两行
    16. Row {
    17. spacing: 20
    18. RadioButton {
    19. checked: true
    20. text: "中国"
    21. }
    22. RadioButton {
    23. text: "美国"
    24. }
    25. RadioButton {
    26. text: "英国"
    27. }
    28. }
    29. Row {
    30. spacing: 20
    31. RadioButton {
    32. checked: true
    33. text: "红色"
    34. }
    35. RadioButton {
    36. text: "绿色"
    37. }
    38. RadioButton {
    39. text: "蓝色"
    40. }
    41. }
    42. }
    43. }
    44. }

    1.2 一行多列

    1. // 行列布局
    2. import QtQuick 2.15
    3. import QtQuick.Window 2.15
    4. import QtQuick.Controls 2.15
    5. Window {
    6. width: 640
    7. height: 480
    8. visible: true
    9. title: qsTr("Hello World")
    10. Item {
    11. anchors.fill: parent
    12. // 一行
    13. Row {
    14. spacing: 20
    15. // 两列
    16. Column {
    17. spacing: 20
    18. RadioButton {
    19. checked: true
    20. text: "中国"
    21. }
    22. RadioButton {
    23. text: "美国"
    24. }
    25. RadioButton {
    26. text: "英国"
    27. }
    28. }
    29. Column {
    30. spacing: 20
    31. RadioButton {
    32. checked: true
    33. text: "红色"
    34. }
    35. RadioButton {
    36. text: "绿色"
    37. }
    38. RadioButton {
    39. text: "蓝色"
    40. }
    41. }
    42. }
    43. }
    44. }

    2.流布局

    2.1 从左向右(默认)

    1. // 流Flow布局
    2. import QtQuick 2.15
    3. import QtQuick.Window 2.15
    4. import QtQuick.Controls 2.15
    5. Window {
    6. width: 640
    7. height: 480
    8. visible: true
    9. title: qsTr("Hello World")
    10. Item {
    11. id: item
    12. anchors.fill: parent
    13. // 流布局: 设定宽高后自动排列
    14. Flow {
    15. anchors.left: parent.left
    16. anchors.right: parent.right
    17. //flow: Flow.LeftToRight // 默认是从左向右
    18. Rectangle {
    19. height: 100
    20. width: item.width / 3
    21. color: "red"
    22. }
    23. Rectangle {
    24. height: 100
    25. width: item.width / 3
    26. color: "green"
    27. }
    28. Rectangle {
    29. height: 100
    30. width: item.width / 3
    31. color: "red"
    32. }
    33. Rectangle {
    34. height: 100
    35. width: item.width / 3
    36. color: "green"
    37. }
    38. }
    39. }
    40. }

    2.2 从上往下

    1. // 流Flow布局
    2. import QtQuick 2.15
    3. import QtQuick.Window 2.15
    4. import QtQuick.Controls 2.15
    5. Window {
    6. width: 640
    7. height: 480
    8. visible: true
    9. title: qsTr("Hello World")
    10. Item {
    11. id: item
    12. anchors.fill: parent
    13. // 流布局: 设定宽高后自动排列
    14. Flow {
    15. anchors.left: parent.left
    16. anchors.right: parent.right
    17. flow: Flow.TopToBottom
    18. Rectangle {
    19. height: 100
    20. width: item.width / 3
    21. color: "red"
    22. }
    23. Rectangle {
    24. height: 100
    25. width: item.width / 3
    26. color: "green"
    27. }
    28. Rectangle {
    29. height: 100
    30. width: item.width / 3
    31. color: "red"
    32. }
    33. Rectangle {
    34. height: 100
    35. width: item.width / 3
    36. color: "green"
    37. }
    38. }
    39. }
    40. }

    3.网格布局

    3行2列布局演示

    1. // 网格布局
    2. import QtQuick 2.15
    3. import QtQuick.Window 2.15
    4. import QtQuick.Controls 2.15
    5. import QtQuick.Layouts 1.0
    6. Window {
    7. width: 640
    8. height: 480
    9. visible: true
    10. title: qsTr("Hello World")
    11. Item {
    12. id: item
    13. anchors.fill: parent
    14. // 网格布局
    15. //GridLayout {
    16. Grid {
    17. id: grid
    18. columns: 2
    19. rows: 3
    20. Text { text: "Three"; font.bold: true; }
    21. Text { text: "words"; color: "red" }
    22. Text { text: "in"; font.underline: true }
    23. Text { text: "a"; font.pixelSize: 20 }
    24. Text { text: "row"; font.strikeout: true }
    25. }
    26. }
    27. }

  • 相关阅读:
    【Redis学习笔记】第二章【2.3】Redis数据类型--list
    mac下mysql 常用命令
    带你一起理解什么是数据库分片?
    同一页面实现recycleView三种布局【recycleView + adapter】
    08.webpack5搭建vue环境(二)
    特斯拉陷入巨大质疑:车祸前1秒,Autopilot自动退出
    B模块windows渗透
    15 Transformer 框架概述
    惯性导航定位技术
    JVM原理及优化_子系统
  • 原文地址:https://blog.csdn.net/hsy12342611/article/details/133295106