当前位置:网站首页>QML学习 第二天
QML学习 第二天
2022-06-12 11:43:00 【波雅_汉库克】
目录
接着昨天.在来学点QML的空间.
Rectangle控件:
今天第一个空间就是Rectangle(矩形),这个控件本来没什么好说的,就是画个矩形,
Rectangle{
x: 100
y: 100
z:1
width: 100
height: 50
color:"black"
}
Rectangle{
x: 120
y: 120
width: 100
height: 50
color:"blue"
}如果要是两个矩阵重合了怎么办,其实还有第三个坐标z,默认z是0,如果设置z为1,就是z大的在上.

focus属性:
这个属性是获取当前焦点的.
Rectangle{
x: 100
y: 100
z:11
width: 100
height: 50
color:"black"
focus:true
//activeFocus:
MouseArea{
anchors.fill:parent
onClicked:{
console.log("on clicked")
}
}
Keys.onReturnPressed:{
console.log("on clicked")
}
}当把focus这个属性设置为true就可以获取这个矩形控件的焦点.如果单击这个矩形就会触发打印 on clicked,下面这段代码.
MouseArea{
anchors.fill:parent
onClicked:{
console.log("on clicked")
}当键盘获取矩形的焦点按下回车也会触发 打印 on clicked
下面代码:
Keys.onReturnPressed:{
console.log("on clicked")
}当focus设置为false或者没有就不会获取焦点,上面两个操作也就没有了.
锚点:
Rectangle
{
id:rect1
width: 100
height: 50
color: "black"
}
Rectangle
{
x:rect1.width + 20
id:rect2
width: 100
height: 50
color: "black"
}结果:

通过锚点实现:
Rectangle
{
id:rect1
width: 100
height: 50
color: "black"
}
Rectangle
{
id:rect2
width: 100
height: 50
color: "black"
anchors.left: rect1.right
anchors.leftMargin: 20
}
// Reanchors.left: rect1.right rect2的左边等于rect1的右边
anchors.leftMargin: 20 左边间隔20

矩形居中与父控件:
Rectangle
{
id:rect2
width: 100
height: 50
color: "black"
anchors.centerIn: parent
}
当然水平和垂直都可以.
旋转属性rotation:
旋转30度
Rectangle
{
id:rect2
width: 100
height: 50
color: "black"
rotation: 30
}

放缩属性scale:
Rectangle
{
id:rect2
x:100
y:100
width: 100
height: 50
color: "black"
rotation: 30
scale: 2
}
设置矩形的边控border:
Rectangle
{
id:rect2
x:100
y:100
width: 100
height: 50
color: "black"
rotation: 30
scale: 2
border.width: 2
border.color:"red"
}
矩形圆角弧度 radius:
Rectangle
{
id:rect2
x:100
y:100
width: 100
height: 50
color: "black"
rotation: 30
scale: 2
border.width: 2
border.color:"red"
radius: 15
}

qml导入外部的矩形,在另外的一个qml中定义的
边栏推荐
- 字节序(网络/主机)转换
- Windows10 install mysql-8.0.28-winx64
- FormatConversionTool. exe
- 7-5 复数四则运算
- 【数据库】sqlite版本升级、降级
- 【深度学习基础】反向传播法(1)
- Who moved my package lock
- Les humains veulent de l'argent, du pouvoir, de la beauté, de l'immortalité, du bonheur... Mais les tortues ne veulent être qu'une tortue.
- IP地址管理
- M-arch (fanwai 10) gd32l233 evaluation -spi drive DS1302
猜你喜欢

Compiling Draco library on Windows platform

ARM指令集之批量Load/Store指令

Windows10 install mysql-8.0.28-winx64

21 reasons why you need social media QR code

6.6 separate convolution

Relation entre les classes et à l'intérieur des classes de classification vidéo - - Régularisation

Byte order - how to judge the big end and the small end

K52. Chapter 1: installing kubernetes v1.22 based on kubeadm -- cluster deployment

A.前缀极差

Unity 连接 Microsoft SQLSERVER 数据库
随机推荐
【藍橋杯單片機 國賽 第十一届】
[cf1392d] D. Omkar and bed Wars
套接字编程Udp篇
6.6 separate convolution
How to view glibc version
TinyMCE realizes automatic uploading of pasted pictures
Go sends SMS based on Tencent cloud
Node crawler puppeter usage
35. 搜索插入位置
ARM指令集之跳转指令
Who moved my package lock
标品和非标品如何选品,选品的重要性,店铺怎样布局
影响店铺权重的三十一条,快来看看中招了吗
conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)
Unit test case framework --unittest
Relation entre les classes et à l'intérieur des classes de classification vidéo - - Régularisation
Reentrantlock source code analysis
K53. Chapter 2 installing kubernetes v1.22 based on binary packages -- cluster deployment
正则表达式 | 浅解
Relatively rare exception records in UI automation test