Qt_Note8_QML_Rectangle

QML&Rectangle

main.qml

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.5

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("My QML")
    color: "white"

    MyRectangle {
        x: 100
        y: 50
        width: 200
        height: 100
//        myTopMargin: 10
//        myBottomMargin: 10
    }

//    Rectangle {
//        x: 100
//        y: 30
//        width: 100
//        height: 50
//        color: "black"
        anchors.centerIn: parent    //居中于父控件
        anchors.horizontalCenter: parent.horizontalCenter //水平居中
        anchors.verticalCenter: parent.verticalCenter //垂直居中

        rotation: 30  //旋转

        scale: 0.5  //放缩

        antialiasing: false //抗锯齿

//        //边框
//        border.width: 5
//        border.color: "red"

//        //圆角弧度
//        radius: 15

//    }

    //GradientStop颜色层次变化效果
//    Rectangle {
//          y: 100; width: 80; height: 80
//          rotation: 45
//          gradient: Gradient {
//              GradientStop { position: 0.0; color: "lightsteelblue" }
//              GradientStop { position: 1.0; color: "blue" }
//          }
//      }

//    Rectangle {
//        x: 50
//        y: 30
//        width: 100
//        height: 50
//        border.width: 5
//        border.color: "black"
//    }

    //坐标 z 使用;焦点使用;
//    Rectangle {
//        x: 100
//        y: 100
//        z: 3
//        width: 100
//        height: 50
//        color: "black"
//        focus: true //焦点
//        //activeFocus:

//        MouseArea {
//            anchors.fill: parent
//            onClicked: {
//                console.log("on clicked")
//            }
//        }
//        Keys.onReturnPressed: {
//            console.log("on return pressed")
//        }
//    }

//    Rectangle {
//        x: 120
//        y: 120
//        width: 100
//        height: 50
//        color: "blue"
//    }

//    Rectangle {
//        x: 140
//        y: 140
//        z: 2
//        width: 100
//        height: 50
//        color: "green"
//    }

    //锚点anchor使用
//    Rectangle {
//        id: rect1
        anchors.fill: parent    //填充在父控件当中
//        width: 100
//        height: 50
//        color: "black"
//    }

//    Rectangle {
        x: rect1.width + 20
//        id: rect2
//        width: 100
//        height: 50
//        anchors.left: rect1.right   //使用锚点,将两个矩形挨在一起
//        anchors.leftMargin: 20
//        color: "black"
//    }

//    Rectangle {
//        id: rect3
//        width: 100
//        height: 50
//        anchors.top: rect1.bottom
//        anchors.topMargin: 20
//        color: "black"
//    }
}

MyRectangle.qml

import QtQuick 2.0

Rectangle {
    id: borderRect
    property int myTopMargin: 0
    property int myBottomMargin: 0
    width: 200
    height: 100
    color: "black"
    Rectangle {
        id: innerRect
        color: "blue"
        anchors.fill: parent
        anchors.topMargin: myTopMargin
        anchors.bottomMargin: myBottomMargin
        anchors.leftMargin: 5
        anchors.rightMargin: 5
    }
}

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可可西里啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值