Qt/QML学习-定位器

QML学习

在这里插入图片描述

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("positioner")

    Rectangle {
        id: rectColumn
        width: parent.width / 2
        height: parent.height / 2
        border.width: 1
        Column {
            anchors.fill: parent
            spacing: 10
            Repeater {
                model: 4
                delegate: Rectangle {
                    width: 50; height: 50
                    border.width: 1
                    color: "yellow"
                    opacity: 0.5
                }
            }
        }
        Text {
            text: qsTr("Column")
            anchors.centerIn: parent
            font.pointSize: 30
        }
    }
    Rectangle {
        id: rectFlow
        width: parent.width / 2
        height: parent.height / 2
        border.width: 1
        anchors.left: rectColumn.right
        Flow {
            anchors.fill: parent
            spacing: 10
            Repeater {
                model: 4
                delegate: Rectangle {
                    width: 50; height: 50
                    border.width: 1
                    color: "yellow"
                    opacity: 0.5
                }
            }
        }
        Text {
            text: qsTr("Flow")
            anchors.centerIn: parent
            font.pointSize: 30
        }
    }
    Rectangle {
        id: rectGrid
        width: parent.width / 2
        height: parent.height / 2
        border.width: 1
        anchors.top: rectColumn.bottom
        Grid {
            anchors.fill: parent
            spacing: 10
            columns: 3 // 设置列数为3
            rows: 2 // 设置行数为2
            Repeater {
                model: 4
                delegate: Rectangle {
                    width: 50; height: 50
                    border.width: 1
                    color: "yellow"
                    opacity: 0.5
                }
            }
        }
        Text {
            text: qsTr("Grid")
            anchors.centerIn: parent
            font.pointSize: 30
        }
    }
    Rectangle {
        id: rectRow
        width: parent.width / 2
        height: parent.height / 2
        border.width: 1
        anchors.left: rectGrid.right
        anchors.top: rectColumn.bottom
        Row {
            anchors.fill: parent
            spacing: 10
            Repeater {
                model: 4
                delegate: Rectangle {
                    width: 50; height: 50
                    border.width: 1
                    color: "yellow"
                    opacity: 0.5
                }
            }
        }
        Text {
            text: qsTr("Row")
            anchors.centerIn: parent
            font.pointSize: 30
        }
    }
}

演示

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 11:52:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 11:52:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 11:52:02       58 阅读
  4. Python语言-面向对象

    2024-07-14 11:52:02       69 阅读

热门阅读

  1. GESP:2024-6月等级5-T1-黑白格

    2024-07-14 11:52:02       23 阅读
  2. Postman API版本控制:最佳实践指南

    2024-07-14 11:52:02       21 阅读
  3. 数仓工具—Hive基础之临时表及示例

    2024-07-14 11:52:02       23 阅读
  4. 用C在安卓手机上开发

    2024-07-14 11:52:02       29 阅读
  5. sqlserver 表大小查询

    2024-07-14 11:52:02       22 阅读
  6. Nginx源码安装

    2024-07-14 11:52:02       21 阅读
  7. 使用Windows.size()定义窗口大小

    2024-07-14 11:52:02       16 阅读
  8. C#字符串

    2024-07-14 11:52:02       21 阅读
  9. Ansible 安装及使用说明

    2024-07-14 11:52:02       27 阅读
  10. PyCharm 查找功能指南

    2024-07-14 11:52:02       26 阅读